home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / lisp / packages / ispell.el < prev    next >
Encoding:
Text File  |  1995-08-11  |  89.7 KB  |  2,343 lines

  1. ;;; GNU EMACS interface for International Ispell Version 3.1 by Geoff Kuenning.
  2. ;;;
  3. ;;;
  4. ;;; Copyright (C) 1994 Free Software Foundation, Inc.
  5. ;;;
  6. ;;;
  7. ;;; Authors         : Ken Stevens <k.stevens@ieee.org>
  8. ;;; Last Modified On: Fri Jan 13 14:16:46 EST 1995
  9. ;;; Update Revision : 2.35
  10. ;;; Syntax          : emacs-lisp
  11. ;;; Status        : Release with 3.1.14+ ispell.
  12. ;;; Version        : International Ispell Version 3.1 by Geoff Kuenning.
  13. ;;; Bug Reports        : ispell-el-bugs@itcorp.com
  14. ;;;
  15. ;; This file is part of XEmacs.
  16.  
  17. ;; XEmacs is free software; you can redistribute it and/or modify it
  18. ;; under the terms of the GNU General Public License as published by
  19. ;; the Free Software Foundation; either version 2, or (at your option)
  20. ;; any later version.
  21.  
  22. ;; XEmacs is distributed in the hope that it will be useful, but
  23. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  24. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  25. ;; General Public License for more details.
  26.  
  27. ;; You should have received a copy of the GNU General Public License
  28. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  29. ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  30. ;;;
  31. ;;; Commentary:
  32. ;;;
  33. ;;; INSTRUCTIONS
  34. ;;;
  35. ;;;  This code contains a section of user-settable variables that you should
  36. ;;; inspect prior to installation.  Look past the end of the history list.
  37. ;;; Set them up for your locale and the preferences of the majority of the
  38. ;;; users.  Otherwise the users may need to set a number of variables
  39. ;;; themselves.
  40. ;;;  You particularly may want to change the default dictionary for your
  41. ;;; country and language.
  42. ;;;
  43. ;;;
  44. ;;; To fully install this, add this file to your Emacs Lisp directory and
  45. ;;; compile it with M-X byte-compile-file.  Then add the following to the
  46. ;;; appropriate init file:
  47. ;;;
  48. ;;;  (autoload 'ispell-word "ispell"
  49. ;;;    "Check the spelling of word in buffer." t)
  50. ;;;  (global-set-key "\e$" 'ispell-word)
  51. ;;;  (autoload 'ispell-region "ispell"
  52. ;;;    "Check the spelling of region." t)
  53. ;;;  (autoload 'ispell-buffer "ispell"
  54. ;;;    "Check the spelling of buffer." t)
  55. ;;;  (autoload 'ispell-complete-word "ispell"
  56. ;;;    "Look up current word in dictionary and try to complete it." t)
  57. ;;;  (autoload 'ispell-change-dictionary "ispell"
  58. ;;;    "Change ispell dictionary." t)
  59. ;;;  (autoload 'ispell-message "ispell"
  60. ;;;    "Check spelling of mail message or news post.")
  61. ;;;
  62. ;;;  Depending on the mail system you use, you may want to include these:
  63. ;;;
  64. ;;;  (add-hook 'news-inews-hook 'ispell-message)
  65. ;;;  (add-hook 'mail-send-hook  'ispell-message)
  66. ;;;  (add-hook 'mh-before-send-letter-hook 'ispell-message)
  67. ;;;
  68. ;;;
  69. ;;; Ispell has a TeX parser and a nroff parser (the default).
  70. ;;; The parsing is controlled by the variable ispell-parser.  Currently
  71. ;;; it is just a "toggle" between TeX and nroff, but if more parsers are
  72. ;;; added it will be updated.  See the variable description for more info.
  73. ;;;
  74. ;;;
  75. ;;; TABLE OF CONTENTS
  76. ;;;
  77. ;;;   ispell-word
  78. ;;;   ispell-region
  79. ;;;   ispell-buffer
  80. ;;;   ispell-message
  81. ;;;   ispell-continue
  82. ;;;   ispell-complete-word
  83. ;;;   ispell-complete-word-interior-frag
  84. ;;;   ispell-change-dictionary
  85. ;;;   ispell-kill-ispell
  86. ;;;   ispell-pdict-save
  87. ;;;
  88. ;;;
  89. ;;; Commands in ispell-region:
  90. ;;; Character replacement: Replace word with choice.  May query-replace.
  91. ;;; ' ': Accept word this time.
  92. ;;; 'i': Accept word and insert into private dictionary.
  93. ;;; 'a': Accept word for this session.
  94. ;;; 'A': Accept word and place in buffer-local dictionary.
  95. ;;; 'r': Replace word with typed-in value.  Rechecked.
  96. ;;; 'R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
  97. ;;; '?': Show these commands
  98. ;;; 'x': Exit spelling buffer.  Move cursor to original point.
  99. ;;; 'X': Exit spelling buffer.  Leave cursor at the current point.
  100. ;;; 'q': Quit spelling session (Kills ispell process).
  101. ;;; 'l': Look up typed-in replacement in alternate dictionary.  Wildcards okay.
  102. ;;; 'u': Like 'i', but the word is lower-cased first.
  103. ;;; 'm': Like 'i', but allows one to include dictionary completion info.
  104. ;;; 'C-l': redraws screen
  105. ;;; 'C-r': recursive edit
  106. ;;; 'C-z': suspend emacs or iconify frame
  107. ;;;
  108. ;;; Buffer-Local features:
  109. ;;; There are a number of buffer-local features that can be used to customize
  110. ;;;  ispell for the current buffer.  This includes language dictionaries,
  111. ;;;  personal dictionaries, parsing, and local word spellings.  Each of these
  112. ;;;  local customizations are done either through local variables, or by
  113. ;;;  including the keyword and argument(s) at the end of the buffer (usually
  114. ;;;  prefixed by the comment characters).  See the end of this file for
  115. ;;;  examples.  The local keywords and variables are:
  116. ;;;
  117. ;;;  ispell-dictionary-keyword   language-dictionary
  118. ;;;      uses local variable ispell-local-dictionary
  119. ;;;  ispell-pdict-keyword        personal-dictionary
  120. ;;;      uses local variable ispell-local-pdict
  121. ;;;  ispell-parsing-keyword      mode-arg extended-char-arg
  122. ;;;  ispell-words-keyword        any number of local word spellings
  123. ;;;
  124. ;;;
  125. ;;; BUGS:
  126. ;;;  Highlighting in version 19 still doesn't work on tty's.
  127. ;;;  On some versions of emacs, growing the minibuffer fails.
  128. ;;;
  129. ;;; HISTORY
  130. ;;;
  131. ;;; Revision 2.35  1995/1/13 14:16:46    stevens
  132. ;;; Skips SGML tags, ispell-change-dictionary fix for add-hook, assure personal
  133. ;;; dictionary is saved when called from the menu
  134. ;;;
  135. ;;; Revision 2.34  1994/12/08 13:17:41  stevens
  136. ;;; Interaction corrected to function with all 3.1 ispell versions.
  137. ;;;
  138. ;;; Revision 2.33  1994/11/24 02:31:20  stevens
  139. ;;; Repaired bug introduced in 2.32 that corrupts buffers when correcting.
  140. ;;; Improved buffer scrolling. Nondestructive buffer selections allowed.
  141. ;;;
  142. ;;; Revision 2.32  1994/10/31 21:10:08  geoff
  143. ;;; Many revisions accepted from RMS/FSF.  I think (though I don't know) that
  144. ;;; this represents an 'official' version.
  145. ;;;
  146. ;;; Revision 2.31  1994/5/31 10:18:17  stevens
  147. ;;; Repaired comments.  buffer-local commands executed in `ispell-word' now.
  148. ;;; German dictionary described for extended character mode.  Dict messages.
  149. ;;;
  150. ;;; Revision 2.30  1994/5/20 22:18:36  stevens
  151. ;;; Continue ispell from ispell-word, C-z functionality fixed.
  152. ;;;
  153. ;;; Revision 2.29  1994/5/12 09:44:33  stevens
  154. ;;; Restored ispell-use-ptys-p, ispell-message aborts sends with interrupt.
  155. ;;; defined fn ispell
  156. ;;;
  157. ;;; Revision 2.28  1994/4/28 16:24:40  stevens
  158. ;;; Window checking when ispell-message put on gnus-inews-article-hook jwz.
  159. ;;; prefixed ispell- to highlight functions and horiz-scroll fn.
  160. ;;; Try and respect case of word in ispell-complete-word.
  161. ;;; Ignore non-char events.  Ispell-use-ptys-p commented out. Lucid menu.
  162. ;;; Better interrupt handling.  ispell-message improvements from Ethan.
  163. ;;;
  164. ;;; Revision 2.27
  165. ;;; version 18 explicit C-g handling disabled as it didn't work. Added
  166. ;;; ispell-extra-args for ispell customization (jwz)
  167. ;;;
  168. ;;; Revision 2.26  1994/2/15 16:11:14  stevens
  169. ;;; name changes for copyright assignment.  Added word-frags in complete-word.
  170. ;;; Horizontal scroll (John Conover). Query-replace matches words now.  bugs.
  171. ;;;
  172. ;;; Revision 2.25
  173. ;;; minor mods, upgraded ispell-message
  174. ;;;
  175. ;;; Revision 2.24
  176. ;;; query-replace more robust, messages, defaults, ispell-change-dict.
  177. ;;;
  178. ;;; Revision 2.23  1993/11/22 23:47:03  stevens
  179. ;;; ispell-message, Fixed highlighting, added menu-bar, fixed ispell-help, ...
  180. ;;;
  181. ;;; Revision 2.22
  182. ;;; Added 'u' command.  Fixed default in ispell-local-dictionary.
  183. ;;; fixed affix rules display.  Tib skipping more robust.  Contributions by
  184. ;;; Per Abraham (parser selection), Denis Howe, and Eberhard Mattes.
  185. ;;;
  186. ;;; Revision 2.21  1993/06/30 14:09:04  stevens
  187. ;;; minor bugs. (nroff word skipping fixed)
  188. ;;;
  189. ;;; Revision 2.20  1993/06/30 14:09:04  stevens
  190. ;;;
  191. ;;; Debugging and contributions by: Boris Aronov, Rik Faith, Chris Moore,
  192. ;;;  Kevin Rodgers, Malcolm Davis.
  193. ;;; Particular thanks to Michael Lipp, Jamie Zawinski, Phil Queinnec
  194. ;;;  and John Heidemann for suggestions and code.
  195. ;;; Major update including many tweaks.
  196. ;;; Many changes were integrations of suggestions.
  197. ;;; lookup-words rehacked to use call-process (Jamie).
  198. ;;; ispell-complete-word rehacked to be compatible with the rest of the
  199. ;;; system for word searching and to include multiple wildcards,
  200. ;;; and it's own dictionary.
  201. ;;; query-replace capability added.  New options 'X', 'R', and 'A'.
  202. ;;; buffer-local modes for dictionary, word-spelling, and formatter-parsing.
  203. ;;; Many random bugs, like commented comments being skipped, fix to
  204. ;;; keep-choices-win, fix for math mode, added pipe mode choice,
  205. ;;; fixed 'q' command, ispell-word checks previous word and leave cursor
  206. ;;; in same location.  Fixed tib code which could drop spelling regions.
  207. ;;; Cleaned up setq calls for efficiency. Gave more context on window overlays.
  208. ;;; Assure context on ispell-command-loop.  Window lossage in look cmd fixed.
  209. ;;; Due to pervasive opinion, common-lisp package syntax removed. Display
  210. ;;; problem when not highlighting.
  211. ;;;
  212. ;;; Revision 2.19  1992/01/10  10:54:08  geoff
  213. ;;; Make another attempt at fixing the "Bogus, dude" problem.  This one is
  214. ;;; less elegant, but has the advantage of working.
  215. ;;;
  216. ;;; Revision 2.18  1992/01/07  10:04:52  geoff
  217. ;;; Fix the "Bogus, Dude" problem in ispell-word.
  218. ;;;
  219. ;;; Revision 2.17  1991/09/12  00:01:42  geoff
  220. ;;; Add some changes to make ispell-complete-word work better, though
  221. ;;; still not perfectly.
  222. ;;;
  223. ;;; Revision 2.16  91/09/04  18:00:52  geoff
  224. ;;; More updates from Sebastian, to make the multiple-dictionary support
  225. ;;; more flexible.
  226. ;;;
  227. ;;; Revision 2.15  91/09/04  17:30:02  geoff
  228. ;;; Sebastian Kremer's tib support
  229. ;;;
  230. ;;; Revision 2.14  91/09/04  16:19:37  geoff
  231. ;;; Don't do set-window-start if the move-to-window-line moved us
  232. ;;; downward, rather than upward.  This prevents getting the buffer all
  233. ;;; confused.  Also, don't use the "not-modified" function to clear the
  234. ;;; modification flag;  instead use set-buffer-modified-p.  This prevents
  235. ;;; extra messages from flashing.
  236. ;;;
  237. ;;; Revision 2.13  91/09/04  14:35:41  geoff
  238. ;;; Fix a spelling error in a comment.  Add code to handshake with the
  239. ;;; ispell process before sending anything to it.
  240. ;;;
  241. ;;; Revision 2.12  91/09/03  20:14:21  geoff
  242. ;;; Add Sebastian Kremer's multiple-language support.
  243. ;;;
  244. ;;;
  245. ;;; Walt Buehring
  246. ;;; Texas Instruments - Computer Science Center
  247. ;;; ARPA:  Buehring%TI-CSL@CSNet-Relay
  248. ;;; UUCP:  {smu, texsun, im4u, rice} ! ti-csl ! buehring
  249. ;;;
  250. ;;; ispell-region and associated routines added by
  251. ;;; Perry Smith
  252. ;;; pedz@bobkat
  253. ;;; Tue Jan 13 20:18:02 CST 1987
  254. ;;;
  255. ;;; extensively modified by Mark Davies and Andrew Vignaux
  256. ;;; {mark,andrew}@vuwcomp
  257. ;;; Sun May 10 11:45:04 NZST 1987
  258. ;;;
  259. ;;; Ken Stevens  ARPA: k.stevens@ieee.org
  260. ;;; Tue Jan  3 16:59:07 PST 1989
  261. ;;; This file has overgone a major overhaul to be compatible with ispell
  262. ;;; version 2.1.  Most of the functions have been totally rewritten, and
  263. ;;; many user-accessible variables have been added.  The syntax table has
  264. ;;; been removed since it didn't work properly anyway, and a filter is
  265. ;;; used rather than a buffer.  Regular expressions are used based on
  266. ;;; ispell's internal definition of characters (see ispell(4)).
  267. ;;; Some new updates:
  268. ;;; - Updated to version 3.0 to include terse processing.
  269. ;;; - Added a variable for the look command.
  270. ;;; - Fixed a bug in ispell-word when cursor is far away from the word
  271. ;;;   that is to be checked.
  272. ;;; - Ispell places the incorrect word or guess in the minibuffer now.
  273. ;;; - fixed a bug with 'l' option when multiple windows are on the screen.
  274. ;;; - lookup-words just didn't work with the process filter.  Fixed.
  275. ;;; - Rewrote the process filter to make it cleaner and more robust
  276. ;;;   in the event of a continued line not being completed.
  277. ;;; - Made ispell-init-process more robust in handling errors.
  278. ;;; - Fixed bug in continuation location after a region has been modified by
  279. ;;;   correcting a misspelling.
  280. ;;; Mon 17 Sept 1990
  281. ;;;
  282. ;;; Sebastian Kremer <sk@thp.uni-koeln.de>
  283. ;;; Wed Aug  7 14:02:17 MET DST 1991
  284. ;;; - Ported ispell-complete-word from Ispell 2 to Ispell 3.
  285. ;;; - Added ispell-kill-ispell command.
  286. ;;; - Added ispell-dictionary and ispell-dictionary-alist variables to
  287. ;;;   support other than default language.  See their docstrings and
  288. ;;;   command ispell-change-dictionary.
  289. ;;; - (ispelled it :-)
  290. ;;; - Added ispell-skip-tib variable to support the tib bibliography
  291. ;;;   program.
  292. ;;;
  293. ;;;
  294. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  295.  
  296.  
  297.  
  298. ;;; **********************************************************************
  299. ;;; The following variables should be set according to personal preference
  300. ;;; and location of binaries:
  301. ;;; **********************************************************************
  302.  
  303.  
  304. ;;;  ******* THIS FILE IS WRITTEN FOR ISPELL VERSION 3.1
  305. ;;; Code:
  306.  
  307. (defvar ispell-highlight-p t
  308.   "*Highlight spelling errors when non-nil.")
  309.  
  310. (defvar ispell-highlight-face 'highlight
  311.   "*The face used for Ispell highlighting.  For Emacses with overlays.
  312. Possible values are `highlight', `modeline', `secondary-selection',
  313. `region', and `underline'.
  314. This variable can be set by the user to whatever face they desire.
  315. It's most convenient if the cursor color and highlight color are
  316. slightly different.")
  317.  
  318. (defvar ispell-check-comments nil
  319.   "*Spelling of comments checked when non-nil.")
  320.  
  321. (defvar ispell-query-replace-choices nil
  322.   "*Corrections made throughout region when non-nil.
  323. Uses `query-replace' (\\[query-replace]) for corrections.")
  324.  
  325. (defvar ispell-skip-tib nil
  326.   "*Does not spell check `tib' bibliography references when non-nil.
  327. Skips any text between strings matching regular expressions
  328. `ispell-tib-ref-beginning' and `ispell-tib-ref-end'.
  329.  
  330. TeX users beware:  Any field starting with [. will skip until a .] -- even
  331. your whole buffer -- unless you set `ispell-skip-tib' to nil.  That includes
  332. a [.5mm] type of number....")
  333.  
  334. (defvar ispell-tib-ref-beginning "[[<]\\."
  335.   "Regexp matching the beginning of a Tib reference.")
  336.  
  337. (defvar ispell-tib-ref-end "\\.[]>]"
  338.   "Regexp matching the end of a Tib reference.")
  339.  
  340. (defvar ispell-keep-choices-win t
  341.   "*When not nil, the `*Choices*' window remains for spelling session.
  342. This minimizes redisplay thrashing.")
  343.  
  344. (defvar ispell-choices-win-default-height 2
  345.   "*The default size of the `*Choices*' window, including status line.
  346. Must be greater than 1.")
  347.  
  348. (defvar ispell-program-name "ispell"
  349.   "Program invoked by \\[ispell-word] and \\[ispell-region] commands.")
  350.  
  351. (defvar ispell-alternate-dictionary
  352.   (cond ((file-exists-p "/usr/dict/web2") "/usr/dict/web2")
  353.     ((file-exists-p "/usr/share/dict/web2") "/usr/share/dict/web2")
  354.     ((file-exists-p "/usr/dict/words") "/usr/dict/words")
  355.     ((file-exists-p "/usr/lib/dict/words") "/usr/lib/dict/words")
  356.     ((file-exists-p "/usr/share/dict/words") "/usr/share/dict/words")
  357.     ((file-exists-p "/sys/dict") "/sys/dict")
  358.     (t "/usr/dict/words"))
  359.   "*Alternate dictionary for spelling help.")
  360.  
  361. (defvar ispell-complete-word-dict ispell-alternate-dictionary
  362.   "*Dictionary used for word completion.")
  363.  
  364. (defvar ispell-grep-command "egrep"
  365.   "Name of the grep command for search processes.")
  366.  
  367. (defvar ispell-grep-options "-i"
  368.   "String of options to use when running the program in `ispell-grep-command'.
  369. Should probably be \"-i\" or \"-e\".
  370. Some machines (like the NeXT) don't support \"-i\"")
  371.  
  372. (defvar ispell-look-command "look"
  373.   "Name of the look command for search processes.
  374. This must be an absolute file name.")
  375.  
  376. (defvar ispell-look-p (file-exists-p ispell-look-command)
  377.   "*Non-nil means use `look' rather than `grep'.
  378. Default is based on whether `look' seems to be available.")
  379.  
  380. (defvar ispell-have-new-look nil
  381.   "*Non-nil means use the `-r' option (regexp) when running `look'.")
  382.  
  383. (defvar ispell-look-options (if ispell-have-new-look "-dfr" "-df")
  384.   "String of command options for `ispell-look-command'.")
  385.  
  386. (defvar ispell-use-ptys-p nil
  387.   "When non-nil, Emacs uses ptys to communicate with Ispell.
  388. When nil, Emacs uses pipes.")
  389.  
  390. (defvar ispell-following-word nil
  391.   "*Non-nil means `ispell-word' checks the word around or after point.
  392. Otherwise `ispell-word' checks the preceding word.")
  393.  
  394. (defvar ispell-help-in-bufferp nil
  395.   "*Non-nil means display interactive keymap help in a buffer.
  396. Otherwise use the minibuffer.")
  397.  
  398. (defvar ispell-quietly nil
  399.   "*Non-nil means suppress messages in `ispell-word'.")
  400.  
  401. (defvar ispell-format-word (function upcase)
  402.   "*Formatting function for displaying word being spell checked.
  403. The function must take one string argument and return a string.")
  404.  
  405. ;; XEmacs change - ispell-local-pdict depends on this
  406. ;;;###autoload
  407. (defvar ispell-personal-dictionary nil
  408.   "*File name of your personal spelling dictionary, or nil.
  409. If nil, the default personal dictionary, \"~/.ispell_DICTNAME\" is used,
  410. where DICTNAME is the name of your default dictionary.")
  411.  
  412. (defvar ispell-silently-savep nil
  413.   "*When non-nil, save the personal dictionary without confirmation.")
  414.  
  415. ;;; This variable contains the current dictionary being used if the ispell
  416. ;;; process is running.  Otherwise it contains the global default.
  417. (defvar ispell-dictionary nil
  418.   "If non-nil, a dictionary to use instead of the default one.
  419. This is passed to the ispell process using the `-d' switch and is
  420. used as key in `ispell-dictionary-alist' (which see).
  421.  
  422. You should set this variable before your first use of Emacs spell-checking
  423. commands in the Emacs session, or else use the \\[ispell-change-dictionary]
  424. command to change it.  Otherwise, this variable only takes effect in a newly
  425. started Ispell process.")
  426.  
  427. (defvar ispell-extra-args nil
  428.   "*If non-nil, a list of extra switches to pass to the Ispell program.
  429. For example, '(\"-W\" \"3\") to cause it to accept all 1-3 character
  430. words as correct.  See also `ispell-dictionary-alist', which may be used
  431. for language-specific arguments.")
  432.  
  433. ;;;###autoload
  434. (defvar ispell-dictionary-alist-1    ; sk  9-Aug-1991 18:28
  435.   '((nil                ; default (english.aff)
  436.      "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil)
  437.     ("english"                ; make english explicitly selectable
  438.      "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil)
  439.     ("british"                ; british version
  440.      "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B" "-d" "british") nil)
  441.     ("deutsch"                ; deutsch.aff
  442.      "[a-zA-Z\"]" "[^a-zA-Z\"]" "[']" t ("-C") "~tex")
  443.     ("deutsch8"
  444.      "[a-zA-Z\304\326\334\344\366\337\374]"
  445.      "[^a-zA-Z\304\326\334\344\366\337\374]"
  446.      "[']" t ("-C" "-d" "deutsch") "~latin1")
  447.     ("nederlands"                ; nederlands.aff
  448.      "[A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]"
  449.      "[^A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]"
  450.      "[']" t ("-C") nil)
  451.     ("nederlands8"                ; dutch8.aff
  452.      "[A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]"
  453.      "[^A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]"
  454.      "[']" t ("-C") nil)))
  455.  
  456. ;;;###autoload
  457. (defvar ispell-dictionary-alist-2
  458.   '(("svenska"                ;7 bit swedish mode
  459.      "[A-Za-z}{|\\133\\135\\\\]" "[^A-Za-z}{|\\133\\135\\\\]"
  460.      "[']" nil ("-C") nil)
  461.     ("svenska8"                ;8 bit swedish mode
  462.      "[A-Za-z\345\344\366\305\304\366]"  "[^A-Za-z\345\344\366\305\304\366]"
  463.      "[']" nil ("-C" "-d" "svenska") "~list") ; Add `"-T" "list"' instead?
  464.     ("francais7"
  465.      "[A-Za-z]" "[^A-Za-z]" "[`'^---]" t nil nil)
  466.     ("francais"                ; francais.aff
  467.      "[A-Za-z\300\302\306\307\310\311\312\313\316\317\324\331\333\334\340\342\347\350\351\352\353\356\357\364\371\373\374]"
  468.      "[^A-Za-z\300\302\306\307\310\311\312\313\316\317\324\331\333\334\340\342\347\350\351\352\353\356\357\364\371\373\374]"
  469.      "[---']" t nil "~list")
  470.     ("francais-tex"            ; francais.aff
  471.      "[A-Za-z\300\302\306\307\310\311\312\313\316\317\324\331\333\334\340\342\347\350\351\352\353\356\357\364\371\373\374\\]"
  472.      "[^A-Za-z\300\302\306\307\310\311\312\313\316\317\324\331\333\334\340\342\347\350\351\352\353\356\357\364\371\373\374\\]"
  473.      "[---'^`\"]" t nil "~tex")
  474.     ("dansk"                ; dansk.aff
  475.      "[A-Z\306\330\305a-z\346\370\345]" "[^A-Z\306\330\305a-z\346\370\345]"
  476.      "" nil ("-C") nil)
  477.     ))
  478.  
  479.  
  480. ;;; ispell-dictionary-alist is set up from two subvariables above
  481. ;;; to avoid having very long lines in loaddefs.el.
  482. ;;;###autoload
  483. (defvar ispell-dictionary-alist
  484.   (append ispell-dictionary-alist-1 ispell-dictionary-alist-2)
  485.   "An alist of dictionaries and their associated parameters.
  486.  
  487. Each element of this list is also a list:
  488.  
  489. \(DICTIONARY-NAME CASECHARS NOT-CASECHARS OTHERCHARS MANY-OTHERCHARS-P
  490.         ISPELL-ARGS EXTENDED-CHARACTER-MODE\)
  491.  
  492. DICTIONARY-NAME is a possible value of variable `ispell-dictionary', nil
  493. means the default dictionary.
  494.  
  495. CASECHARS is a regular expression of valid characters that comprise a
  496. word.
  497.  
  498. NOT-CASECHARS is the opposite regexp of CASECHARS.
  499.  
  500. OTHERCHARS is a regular expression of other characters that are valid
  501. in word constructs.  Otherchars cannot be adjacent to each other in a
  502. word, nor can they begin or end a word.  This implies we can't check
  503. \"Stevens'\" as a correct possessive and other correct formations.
  504.  
  505. Hint: regexp syntax requires the hyphen to be declared first here.
  506.  
  507. MANY-OTHERCHARS-P is non-nil if many otherchars are to be allowed in a
  508. word instead of only one.
  509.  
  510. ISPELL-ARGS is a list of additional arguments passed to the ispell
  511. subprocess.
  512.  
  513. EXTENDED-CHARACTER-MODE should be used when dictionaries are used which
  514. have been configured in an Ispell affix file.  (For example, umlauts
  515. can be encoded as \\\"a, a\\\", \"a, ...)  Defaults are ~tex and ~nroff
  516. in English.  This has the same effect as the command-line `-T' option.
  517. The buffer Major Mode controls Ispell's parsing in tex or nroff mode,
  518. but the dictionary can control the extended character mode.
  519. Both defaults can be overruled in a buffer-local fashion. See
  520. `ispell-parsing-keyword' for details on this.
  521.  
  522. Note that the CASECHARS and OTHERCHARS slots of the alist should
  523. contain the same character set as casechars and otherchars in the
  524. language.aff file \(e.g., english.aff\).")
  525.  
  526.  
  527. ;;;###autoload
  528. (defvar ispell-menu-map nil "Key map for ispell menu")
  529.  
  530. ;;;###autoload
  531. (defvar ispell-menu-lucid nil "Spelling menu for Lucid Emacs.")
  532.  
  533. ;;; Break out lucid menu and split into several calls to avoid having
  534. ;;; long lines in loaddefs.el.  Detect need off following constant.
  535.  
  536. ;;;###autoload
  537. (defconst ispell-menu-map-needed    ; make sure this is not Lucid Emacs
  538.   (and (not ispell-menu-map)
  539.        ;; make sure this isn't Lucid Emacs
  540.        (featurep 'menu-bar) (string-lessp "19" emacs-version)))
  541.  
  542.  
  543. ;;; setup dictionary
  544. ;;;###autoload
  545. (if ispell-menu-map-needed
  546.     (let ((dicts (reverse (cons (cons "default" nil) ispell-dictionary-alist)))
  547.       name)
  548.       (setq ispell-menu-map (make-sparse-keymap "Spell"))
  549.       ;; add the dictionaries to the bottom of the list.
  550.       (while dicts
  551.     (setq name (car (car dicts))
  552.           dicts (cdr dicts))
  553.     (if (stringp name)
  554.         (define-key ispell-menu-map (vector (intern name))
  555.           (cons (concat "Select " (capitalize name))
  556.             (list 'lambda () '(interactive)
  557.               (list 'ispell-change-dictionary name))))))))
  558.  
  559. ;;; define commands in menu in opposite order you want them to appear.
  560. ;;;###autoload
  561. (if ispell-menu-map-needed
  562.     (progn
  563.       (define-key ispell-menu-map [ispell-change-dictionary]
  564.     '("Change Dictionary" . ispell-change-dictionary))
  565.       (define-key ispell-menu-map [ispell-kill-ispell]
  566.     '("Kill Process" . ispell-kill-ispell))
  567.       (define-key ispell-menu-map [ispell-pdict-save]
  568.     '("Save Dictionary" . (lambda () (interactive) (ispell-pdict-save t t))))
  569.       (define-key ispell-menu-map [ispell-complete-word]
  570.     '("Complete Word" . ispell-complete-word))
  571.       (define-key ispell-menu-map [ispell-complete-word-interior-frag]
  572.     '("Complete Word Frag" . ispell-complete-word-interior-frag))))
  573.  
  574. ;;;###autoload
  575. (if ispell-menu-map-needed
  576.     (progn
  577.       (define-key ispell-menu-map [ispell-continue]
  578.     '("Continue Check" . ispell-continue))
  579.       (define-key ispell-menu-map [ispell-word]
  580.     '("Check Word" . ispell-word))
  581.       (define-key ispell-menu-map [ispell-region]
  582.     '("Check Region" . ispell-region))
  583.       (define-key ispell-menu-map [ispell-buffer]
  584.     '("Check Buffer" . ispell-buffer))))
  585.  
  586. ;;;###autoload
  587. (if ispell-menu-map-needed
  588.     (progn
  589.       (define-key ispell-menu-map [ispell-message]
  590.     '("Check Message" . ispell-message))
  591.       (define-key ispell-menu-map [ispell-help]
  592.     ;; use (x-popup-menu last-nonmenu-event(list "" ispell-help-list)) ?
  593.     '("Help" . (lambda () (interactive) (describe-function 'ispell-help))))
  594.       (put 'ispell-region 'menu-enable 'mark-active)
  595.       (fset 'ispell-menu-map (symbol-value 'ispell-menu-map))))
  596.  
  597. ;;; XEmacs version 19
  598. (if (and (string-lessp "19" emacs-version)
  599.      (string-match "Lucid" emacs-version)
  600.      (not (and (boundp 'infodock-version) infodock-version)))
  601.     (let ((dicts (cons (cons "default" nil) ispell-dictionary-alist))
  602.       (current-menubar (or current-menubar default-menubar))
  603.       (menu
  604.        '(["Help"        (describe-function 'ispell-help) t]
  605.          ;;["Help"        (popup-menu ispell-help-list)    t]
  606.          ["Check Message"    ispell-message            t]
  607.          ["Check Buffer"    ispell-buffer            t]
  608.          ["Check Word"    ispell-word            t]
  609.          ["Check Region"    ispell-region  (or (not zmacs-regions) (mark))]
  610.          ["Continue Check"    ispell-continue            t]
  611.          ["Complete Word Frag"ispell-complete-word-interior-frag t]
  612.          ["Complete Word"    ispell-complete-word        t]
  613.          ["Kill Process"    ispell-kill-ispell        t]
  614.          "-"
  615.          ["Save Dictionary"    (ispell-pdict-save t t)        t]
  616.          ["Change Dictionary" ispell-change-dictionary    t]))
  617.       name)
  618.       (while dicts
  619.     (setq name (car (car dicts))
  620.           dicts (cdr dicts))
  621.     (if (stringp name)
  622.         (setq menu (append menu
  623.                    (list
  624.                 (vector (concat "Select " (capitalize name))
  625.                     (list 'ispell-change-dictionary name)
  626.                     t))))))
  627.       (setq ispell-menu-lucid menu)
  628.       (if current-menubar
  629.       (progn
  630.         (delete-menu-item '("Edit" "Spell")) ; in case already defined
  631.         (add-menu '("Edit") "Spell" ispell-menu-lucid)))))
  632.  
  633.  
  634. ;;; **********************************************************************
  635. ;;; The following are used by ispell, and should not be changed.
  636. ;;; **********************************************************************
  637.  
  638.  
  639. ;;; The version must be 3.1 or greater for this version of ispell.el
  640. ;;; There is an incompatibility between versin 3.1.12 and lower versions.
  641. (defconst ispell-required-version '("3.1." 12)
  642.   "Ispell versions with which this version of ispell.el is known to work.")
  643. (defvar ispell-offset 1
  644.   "Offset that maps protocol differences between ispell 3.1 versions.")
  645.  
  646. (defun ispell-get-casechars ()
  647.   (nth 1 (assoc ispell-dictionary ispell-dictionary-alist)))
  648. (defun ispell-get-not-casechars ()
  649.   (nth 2 (assoc ispell-dictionary ispell-dictionary-alist)))
  650. (defun ispell-get-otherchars ()
  651.   (nth 3 (assoc ispell-dictionary ispell-dictionary-alist)))
  652. (defun ispell-get-many-otherchars-p ()
  653.   (nth 4 (assoc ispell-dictionary ispell-dictionary-alist)))
  654. (defun ispell-get-ispell-args ()
  655.   (nth 5 (assoc ispell-dictionary ispell-dictionary-alist)))
  656. (defun ispell-get-extended-character-mode ()
  657.   (nth 6 (assoc ispell-dictionary ispell-dictionary-alist)))
  658.  
  659. (defvar ispell-process nil
  660.   "The process object for Ispell.")
  661.  
  662. (defvar ispell-pdict-modified-p nil
  663.   "Non-nil means personal dictionary has modifications to be saved.")
  664.  
  665. ;;; If you want to save the dictionary when quitting, must do so explicitly.
  666. ;;; When non-nil, the spell session is terminated.
  667. ;;; When numeric, contains cursor location in buffer, and cursor remains there.
  668. (defvar ispell-quit nil)
  669.  
  670. (defvar ispell-filter nil
  671.   "Output filter from piped calls to Ispell.")
  672.  
  673. (defvar ispell-filter-continue nil
  674.   "Control variable for Ispell filter function.")
  675.  
  676. (defvar ispell-process-directory nil
  677.   "The directory where `ispell-process' was started.")
  678.  
  679. (defvar ispell-query-replace-marker (make-marker)
  680.   "Marker for `query-replace' processing.")
  681.  
  682. (defvar ispell-checking-message nil
  683.   "Non-nil when we're checking a mail message")
  684.  
  685. (defconst ispell-choices-buffer "*Choices*")
  686.  
  687. (defvar ispell-overlay nil "Overlay variable for Ispell highlighting.")
  688.  
  689. ;;; *** Buffer Local Definitions ***
  690.  
  691. ;;; This is the local dictionary to use.  When nil the default dictionary will
  692. ;;; be used.  Do not redefine default value or it will override the global!
  693. (defvar ispell-local-dictionary nil
  694.   "If non-nil, a dictionary to use for Ispell commands in this buffer.
  695. The value must be a string dictionary name in `ispell-dictionary-alist'.
  696. This variable becomes buffer-local when set in any fashion.
  697.  
  698. Setting ispell-local-dictionary to a value has the same effect as
  699. calling \\[ispell-change-dictionary] with that value.  This variable
  700. is automatically set when defined in the file with either
  701. `ispell-dictionary-keyword' or the Local Variable syntax.")
  702.  
  703. (make-variable-buffer-local 'ispell-local-dictionary)
  704.  
  705. ;; Use default directory, unless locally set.
  706. (set-default 'ispell-local-dictionary nil)
  707.  
  708. (defconst ispell-words-keyword "LocalWords: "                      
  709.   "The keyword for local oddly-spelled words to accept.
  710. The keyword will be followed by any number of local word spellings.
  711. There can be multiple of these keywords in the file.")
  712.  
  713. (defconst ispell-dictionary-keyword "Local IspellDict: "
  714.   "The keyword for local dictionary definitions.
  715. There should be only one dictionary keyword definition per file, and it
  716. should be followed by a correct dictionary name in `ispell-dictionary-alist'.")
  717.  
  718. (defconst ispell-parsing-keyword "Local IspellParsing: "
  719.   "The keyword for overriding default Ispell parsing.
  720. Determined by the buffer's major mode and extended-character mode as well as
  721. the default dictionary.
  722.  
  723. The above keyword string should be followed by `latex-mode' or
  724. `nroff-mode' to put the current buffer into the desired parsing mode.
  725.  
  726. Extended character mode can be changed for this buffer by placing
  727. a `~' followed by an extended-character mode -- such as `~.tex'.")
  728.  
  729. (defvar ispell-skip-sgml-tags nil
  730.   "Skips spell checking of SGML tags when non-nil.
  731. This variable is set when major-mode is sgml-mode.")
  732.  
  733. ;;;###autoload
  734. (defvar ispell-local-pdict ispell-personal-dictionary
  735.   "A buffer local variable containing the current personal dictionary.
  736. If non-nil, the value must be a string, which is a file name.
  737.  
  738. If you specify a personal dictionary for the current buffer which is
  739. different from the current personal dictionary, the effect is similar
  740. to calling \\[ispell-change-dictionary].  This variable is automatically
  741. set when defined in the file with either `ispell-pdict-keyword' or the
  742. local variable syntax.")
  743.  
  744. (make-variable-buffer-local 'ispell-local-pdict)
  745.  
  746. (defconst ispell-pdict-keyword "Local IspellPersDict: "
  747.   "The keyword for defining buffer local dictionaries.")
  748.  
  749. (defvar ispell-buffer-local-name nil
  750.   "Contains the buffer name if local word definitions were used.
  751. Ispell is then restarted because the local words could conflict.")
  752.  
  753. (defvar ispell-parser 'use-mode-name
  754.    "*Indicates whether ispell should parse the current buffer as TeX Code.
  755. Special value `use-mode-name' tries to guess using the name of major-mode.
  756. Default parser is 'nroff.
  757. Currently the only other valid parser is 'tex.
  758.  
  759. You can set this variable in hooks in your init file -- eg:
  760.  
  761. (add-hook 'tex-mode-hook (function (lambda () (setq ispell-parser 'tex))))")
  762.  
  763. (defvar ispell-region-end (make-marker)
  764.   "Marker that allows spelling continuations.")
  765.  
  766. (defvar ispell-check-only nil
  767.   "If non-nil, `ispell-word' does not try to correct the word.")
  768.  
  769.  
  770. ;;; **********************************************************************
  771. ;;; **********************************************************************
  772.  
  773.  
  774. (and (string-lessp "19" emacs-version)
  775.      (not (boundp 'epoch::version))
  776.      (defalias 'ispell 'ispell-buffer))
  777.  
  778. ;;;###autoload (define-key global-map "\M-$" 'ispell-word)
  779.  
  780. ;;;###autoload
  781. (defun ispell-word (&optional following quietly continue)
  782.   "Check spelling of word under or before the cursor.
  783. If the word is not found in dictionary, display possible corrections
  784. in a window allowing you to choose one.
  785.  
  786. With a prefix argument (or if CONTINUE is non-nil),
  787. resume interrupted spell-checking of a buffer or region.
  788.  
  789. If optional argument FOLLOWING is non-nil or if `ispell-following-word'
  790. is non-nil when called interactively, then the following word
  791. \(rather than preceding\) is checked when the cursor is not over a word.
  792. When the optional argument QUIETLY is non-nil or `ispell-quietly' is non-nil
  793. when called interactively, non-corrective messages are suppressed.
  794.  
  795. Word syntax described by `ispell-dictionary-alist' (which see).
  796.  
  797. This will check or reload the dictionary.  Use \\[ispell-change-dictionary]
  798. or \\[ispell-region] to update the Ispell process."
  799.   (interactive (list nil nil current-prefix-arg))
  800.   (if continue
  801.       (ispell-continue)
  802.     (if (interactive-p)
  803.     (setq following ispell-following-word
  804.           quietly ispell-quietly))
  805.     (ispell-accept-buffer-local-defs)    ; use the correct dictionary
  806.     (let ((cursor-location (point))    ; retain cursor location
  807.       (word (ispell-get-word following))
  808.       start end poss replace)
  809.       ;; destructure return word info list.
  810.       (setq start (car (cdr word))
  811.         end (car (cdr (cdr word)))
  812.         word (car word))
  813.  
  814.       ;; now check spelling of word.
  815.       (or quietly
  816.       (message "Checking spelling of %s..."
  817.            (funcall ispell-format-word word)))
  818.       (process-send-string ispell-process "%\n") ;put in verbose mode
  819.       (process-send-string ispell-process (concat "^" word "\n"))
  820.       ;; wait until ispell has processed word
  821.       (while (progn
  822.            (accept-process-output ispell-process)
  823.            (not (string= "" (car ispell-filter)))))
  824.       ;;(process-send-string ispell-process "!\n") ;back to terse mode.
  825.       (setq ispell-filter (cdr ispell-filter))
  826.       (if (listp ispell-filter)
  827.       (setq poss (ispell-parse-output (car ispell-filter))))
  828.       (cond ((eq poss t)
  829.          (or quietly
  830.          (message "%s is correct" (funcall ispell-format-word word))))
  831.         ((stringp poss)
  832.          (or quietly
  833.          (message "%s is correct because of root %s"
  834.               (funcall ispell-format-word word)
  835.               (funcall ispell-format-word poss))))
  836.         ((null poss) (message "Error in ispell process"))
  837.         (ispell-check-only        ; called from ispell minor mode.
  838.          (beep))
  839.         (t                ; prompt for correct word.
  840.          (save-window-excursion
  841.            (setq replace (ispell-command-loop
  842.                   (car (cdr (cdr poss)))
  843.                   (car (cdr (cdr (cdr poss))))
  844.                   (car poss) start end)))
  845.          (cond ((equal 0 replace)
  846.             (ispell-add-per-file-word-list (car poss)))
  847.            (replace
  848.             (setq word (if (atom replace) replace (car replace))
  849.               cursor-location (+ (- (length word) (- end start))
  850.                          cursor-location))
  851.             (if (not (equal word (car poss)))
  852.             (progn
  853.               (delete-region start end)
  854.               (insert word)))
  855.             (if (not (atom replace)) ; recheck spelling of replacement
  856.             (progn
  857.               (goto-char cursor-location)
  858.               (ispell-word following quietly)))))
  859.          (if (get-buffer ispell-choices-buffer)
  860.          (kill-buffer ispell-choices-buffer))))
  861.       (goto-char cursor-location)    ; return to original location
  862.       (ispell-pdict-save ispell-silently-savep)
  863.       (if ispell-quit (setq ispell-quit nil)))))
  864.  
  865.  
  866. (defun ispell-get-word (following &optional extra-otherchars)
  867.   "Return the word for spell-checking according to ispell syntax.
  868. If optional argument FOLLOWING is non-nil or if `ispell-following-word'
  869. is non-nil when called interactively, then the following word
  870. \(rather than preceding\) is checked when the cursor is not over a word.
  871. Optional second argument contains otherchars that can be included in word
  872. many times.
  873.  
  874. Word syntax described by `ispell-dictionary-alist' (which see)."
  875.   (let* ((ispell-casechars (ispell-get-casechars))
  876.      (ispell-not-casechars (ispell-get-not-casechars))
  877.      (ispell-otherchars (ispell-get-otherchars))
  878.      (ispell-many-otherchars-p (ispell-get-many-otherchars-p))
  879.      (word-regexp (concat ispell-casechars
  880.                   "+\\("
  881.                   ispell-otherchars
  882.                   "?"
  883.                   (if extra-otherchars
  884.                   (concat extra-otherchars "?"))
  885.                   ispell-casechars
  886.                   "+\\)"
  887.                   (if (or ispell-many-otherchars-p
  888.                       extra-otherchars)
  889.                   "*" "?")))
  890.      did-it-once
  891.      start end word)
  892.     ;; find the word
  893.     (if (not (looking-at ispell-casechars))
  894.     (if following
  895.         (re-search-forward ispell-casechars (point-max) t)
  896.       (re-search-backward ispell-casechars (point-min) t)))
  897.     ;; move to front of word
  898.     (re-search-backward ispell-not-casechars (point-min) 'start)
  899.     (while (and (or (looking-at ispell-otherchars)
  900.             (and extra-otherchars (looking-at extra-otherchars)))
  901.         (not (bobp))
  902.         (or (not did-it-once)
  903.             ispell-many-otherchars-p))
  904.       (if (and extra-otherchars (looking-at extra-otherchars))
  905.       (progn
  906.         (backward-char 1)
  907.         (if (looking-at ispell-casechars)
  908.         (re-search-backward ispell-not-casechars (point-min) 'move)))
  909.     (setq did-it-once t)
  910.     (backward-char 1)
  911.     (if (looking-at ispell-casechars)
  912.         (re-search-backward ispell-not-casechars (point-min) 'move)
  913.       (backward-char -1))))
  914.     ;; Now mark the word and save to string.
  915.     (or (re-search-forward word-regexp (point-max) t)
  916.     (error "No word found to check!"))
  917.     (setq start (match-beginning 0)
  918.       end (point)
  919.       word (buffer-substring start end))
  920.     (list word start end)))
  921.  
  922.  
  923. ;;; Global ispell-pdict-modified-p is set by ispell-command-loop and
  924. ;;; tracks changes in the dictionary.  The global may either be
  925. ;;; a value or a list, whose value is the state of whether the
  926. ;;; dictionary needs to be saved.
  927.  
  928. (defun ispell-pdict-save (&optional no-query force-save)
  929.   "Check to see if the personal dictionary has been modified.
  930. If so, ask if it needs to be saved."
  931.   (interactive (list ispell-silently-savep t))
  932.   (if (and ispell-pdict-modified-p (listp ispell-pdict-modified-p))
  933.       (setq ispell-pdict-modified-p (car ispell-pdict-modified-p)))
  934.   (if (or ispell-pdict-modified-p force-save)
  935.       (if (or no-query (y-or-n-p "Personal dictionary modified.  Save? "))
  936.       (progn
  937.         (process-send-string ispell-process "#\n")
  938.         (message "Personal dictionary saved."))))
  939.   ;; unassert variable, even if not saved to avoid questioning.
  940.   (setq ispell-pdict-modified-p nil))
  941.  
  942.  
  943. (defun ispell-command-loop (miss guess word start end)
  944.   "Display possible corrections from list MISS.
  945. GUESS lists possibly valid affix construction of WORD.
  946. Returns nil to keep word.
  947. Returns 0 to insert locally into buffer-local dictionary.
  948. Returns string for new chosen word.
  949. Returns list for new replacement word (will be rechecked).
  950. Highlights the word, which is assumed to run from START to END.
  951. Global `ispell-pdict-modified-p' becomes a list where the only value
  952. indicates whether the dictionary has been modified when option `a' or `i' is
  953. used."
  954.   (let ((textbuf (current-buffer))
  955.     (count ?0)
  956.     (line 2)
  957.     (max-lines (- (window-height) 4)) ; assure 4 context lines.
  958.     (choices miss)
  959.     (window-min-height (min window-min-height
  960.                 ispell-choices-win-default-height))
  961.     (command-characters '( ?  ?i ?a ?A ?r ?R ?? ?x ?X ?q ?l ?u ?m ))
  962.     (skipped 0)
  963.     char num result textwin highlighted)
  964.  
  965.     ;; setup the *Choices* buffer with valid data.
  966.     (save-excursion
  967.       (set-buffer (get-buffer-create ispell-choices-buffer))
  968.       (setq mode-line-format "--  %b  --")
  969.       ;; XEmacs: turn off the modeline
  970.       (and (fboundp 'set-specifier)
  971.        (set-specifier has-modeline-p (cons (current-buffer) nil)))
  972.       (erase-buffer)
  973.       (if guess
  974.       (progn
  975.         (insert "Affix rules generate and capitalize "
  976.             "this word as shown below:\n\t")
  977.         (while guess
  978.           (if (> (+ 4 (current-column) (length (car guess)))
  979.              (window-width))
  980.           (progn
  981.             (insert "\n\t")
  982.             (setq line (1+ line))))
  983.           (insert (car guess) "    ")
  984.           (setq guess (cdr guess)))
  985.         (insert "\nUse option `i' if this is a correct composition"
  986.             " from the derivative root.\n")
  987.         (setq line (+ line (if choices 3 2)))))
  988.       (while (and choices
  989.           (< (if (> (+ 7 (current-column) (length (car choices))
  990.                    (if (> count ?~) 3 0))
  991.                 (window-width))
  992.              (progn
  993.                (insert "\n")
  994.                (setq line (1+ line)))
  995.                line)
  996.              max-lines))
  997.     ;; not so good if there are over 20 or 30 options, but then, if
  998.     ;; there are that many you don't want to scan them all anyway...
  999.     (while (memq count command-characters) ; skip command characters.
  1000.       (setq count (1+ count)
  1001.         skipped (1+ skipped)))
  1002.     (insert "(" count ") " (car choices) "  ")
  1003.     (setq choices (cdr choices)
  1004.           count (1+ count)))
  1005.       (setq count (- count ?0 skipped)))
  1006.  
  1007.     ;; Assure word is visible
  1008.     (if (not (pos-visible-in-window-p end))
  1009.     (sit-for 0))
  1010.     ;; Display choices for misspelled word.
  1011.     (let ((choices-window (get-buffer-window ispell-choices-buffer)))
  1012.       (if choices-window
  1013.       (if (not (equal line (window-height choices-window)))
  1014.           ;; *Choices* window changed size.  Adjust the choices window
  1015.           ;; without scrolling the spelled window when possible
  1016.           (let ((window-line (- line (window-height choices-window)))
  1017.             (visible (progn (forward-line -1) (point))))
  1018.         (move-to-window-line 0)
  1019.         (forward-line window-line)
  1020.         (set-window-start (selected-window)
  1021.                   (if (> (point) visible) visible (point)))
  1022.         (goto-char end)
  1023.         (select-window (previous-window)) ; *Choices* window
  1024.         (enlarge-window window-line))
  1025.         (select-window choices-window))
  1026.     ;; Overlay *Choices* window when it isn't showing
  1027.     (ispell-overlay-window (max line ispell-choices-win-default-height)))
  1028.       (switch-to-buffer ispell-choices-buffer)
  1029.       (goto-char (point-min)))
  1030.  
  1031.     (select-window (setq textwin (next-window)))
  1032.  
  1033.     ;; highlight word, protecting current buffer status
  1034.     (unwind-protect
  1035.     (progn
  1036.       (if ispell-highlight-p
  1037.           (ispell-highlight-spelling-error start end t))
  1038.       ;; Loop until a valid choice is made.
  1039.       (while
  1040.           (eq
  1041.            t
  1042.            (setq
  1043.         result
  1044.         (progn
  1045.           (undo-boundary)
  1046.           (message (concat "C-h or ? for more options; SPC to leave "
  1047.                    "unchanged, Character to replace word"))
  1048.           (let ((inhibit-quit t))
  1049.             (setq char (if (fboundp 'read-char-exclusive)
  1050.                    (read-char-exclusive)
  1051.                  (read-char))
  1052.               skipped 0)
  1053.             (if (or quit-flag (= char ?\C-g)) ; C-g is like typing X
  1054.             (setq char ?X
  1055.                   quit-flag nil)))
  1056.           ;; Adjust num to array offset skipping command characters.
  1057.           (let ((com-chars command-characters))
  1058.             (while com-chars
  1059.               (if (and (> (car com-chars) ?0) (< (car com-chars) char))
  1060.               (setq skipped (1+ skipped)))
  1061.               (setq com-chars (cdr com-chars)))
  1062.             (setq num (- char ?0 skipped)))
  1063.  
  1064.           (cond
  1065.            ((= char ? ) nil)    ; accept word this time only
  1066.            ((= char ?i)        ; accept and insert word into pers dict
  1067.             (process-send-string ispell-process (concat "*" word "\n"))
  1068.             (setq ispell-pdict-modified-p '(t)) ; dictionary modified!
  1069.             nil)
  1070.            ((or (= char ?a) (= char ?A)) ; accept word without insert
  1071.             (process-send-string ispell-process (concat "@" word "\n"))
  1072.             (if (null ispell-pdict-modified-p)
  1073.             (setq ispell-pdict-modified-p
  1074.                   (list ispell-pdict-modified-p)))
  1075.             (if (= char ?A) 0))    ; return 0 for ispell-add buffer-local
  1076.            ((or (= char ?r) (= char ?R)) ; type in replacement
  1077.             (if (or (= char ?R) ispell-query-replace-choices)
  1078.             (list (read-string "Query-replacement for: " word) t)
  1079.               (cons (read-string "Replacement for: " word) nil)))
  1080.            ((or (= char ??)
  1081.             ;; XEmacs change: help-char may not be an int.
  1082.             (eq char (event-to-character
  1083.                   (character-to-event help-char)))
  1084.             (= char ?\C-h))
  1085.             (ispell-help)
  1086.             t)
  1087.            ;; Quit and move point back.
  1088.            ((= char ?x)
  1089.             (ispell-pdict-save ispell-silently-savep)
  1090.             (message "Exited spell-checking")
  1091.             (setq ispell-quit t)
  1092.             nil)
  1093.            ;; Quit and preserve point.
  1094.            ((= char ?X)
  1095.             (ispell-pdict-save ispell-silently-savep)
  1096.             (message
  1097.              (substitute-command-keys
  1098.               (concat "Spell-checking suspended;"
  1099.                   " use C-u \\[ispell-word] to resume")))
  1100.             (setq ispell-quit (max (point-min)
  1101.                        (- (point) (length word))))
  1102.             nil)
  1103.            ((= char ?q)
  1104.             (if (y-or-n-p "Really kill Ispell process? ")
  1105.             (progn
  1106.               (ispell-kill-ispell t) ; terminate process.
  1107.               (setq ispell-quit (or (not ispell-checking-message)
  1108.                         (point))
  1109.                 ispell-pdict-modified-p nil))
  1110.               t))        ; continue if they don't quit.
  1111.            ((= char ?l)
  1112.             (let ((new-word (read-string
  1113.                      "Lookup string (`*' is wildcard): "
  1114.                      word))
  1115.               (new-line 2))
  1116.               (if new-word
  1117.               (progn
  1118.                 (save-excursion
  1119.                   (set-buffer (get-buffer-create
  1120.                        ispell-choices-buffer))
  1121.                   (erase-buffer)
  1122.                   (setq count ?0
  1123.                     skipped 0
  1124.                     mode-line-format "--  %b  --"
  1125.                     miss (lookup-words new-word)
  1126.                     choices miss)
  1127.                   (while (and choices ; adjust choices window.
  1128.                       (< (if (> (+ 7 (current-column)
  1129.                                (length (car choices))
  1130.                                (if (> count ?~) 3 0))
  1131.                             (window-width))
  1132.                          (progn
  1133.                            (insert "\n")
  1134.                            (setq new-line
  1135.                              (1+ new-line)))
  1136.                            new-line)
  1137.                          max-lines))
  1138.                 (while (memq count command-characters)
  1139.                   (setq count (1+ count)
  1140.                     skipped (1+ skipped)))
  1141.                 (insert "(" count ") " (car choices) "  ")
  1142.                 (setq choices (cdr choices)
  1143.                       count (1+ count)))
  1144.                   (setq count (- count ?0 skipped)))
  1145.                 (select-window (previous-window))
  1146.                 (if (/= new-line line)
  1147.                 (progn
  1148.                   (if (> new-line line)
  1149.                       (enlarge-window (- new-line line))
  1150.                     (shrink-window (- line new-line)))
  1151.                   (setq line new-line)))
  1152.                 (select-window (next-window)))))
  1153.             t)            ; reselect from new choices
  1154.            ((= char ?u)
  1155.             (process-send-string ispell-process
  1156.                      (concat "*" (downcase word) "\n"))
  1157.             (setq ispell-pdict-modified-p '(t)) ; dictionary modified!
  1158.             nil)
  1159.            ((= char ?m)        ; type in what to insert
  1160.             (process-send-string
  1161.              ispell-process (concat "*" (read-string "Insert: " word)
  1162.                         "\n"))
  1163.             (setq ispell-pdict-modified-p '(t))
  1164.             (cons word nil))
  1165.            ((and (>= num 0) (< num count))
  1166.             (if ispell-query-replace-choices ; Query replace flag
  1167.             (list (nth num miss) 'query-replace)
  1168.               (nth num miss)))
  1169.            ((= char ?\C-l)
  1170.             (redraw-display) t)
  1171.            ((= char ?\C-r)
  1172.             (save-window-excursion (recursive-edit)) t)
  1173.            ((= char ?\C-z)
  1174.             (funcall (key-binding "\C-z"))
  1175.             t)
  1176.            (t (ding) t))))))
  1177.       result)
  1178.       ;; protected
  1179.       (if ispell-highlight-p        ; unhighlight
  1180.       (save-window-excursion
  1181.         (select-window textwin)
  1182.         (ispell-highlight-spelling-error start end))))))
  1183.  
  1184.  
  1185. ;;;###autoload
  1186. (defun ispell-help ()
  1187.   "Display a list of the options available when a misspelling is encountered.
  1188.  
  1189. Selections are:
  1190.  
  1191. DIGIT: Replace the word with a digit offered in the *Choices* buffer.
  1192. SPC:   Accept word this time.
  1193. `i':   Accept word and insert into private dictionary.
  1194. `a':   Accept word for this session.
  1195. `A':   Accept word and place in `buffer-local dictionary'.
  1196. `r':   Replace word with typed-in value.  Rechecked.
  1197. `R':   Replace word with typed-in value. Query-replaced in buffer. Rechecked.
  1198. `?':   Show these commands.
  1199. `x':   Exit spelling buffer.  Move cursor to original point.
  1200. `X':   Exit spelling buffer.  Leaves cursor at the current point, and permits
  1201.         the aborted check to be completed later.
  1202. `q':   Quit spelling session (Kills ispell process).
  1203. `l':   Look up typed-in replacement in alternate dictionary.  Wildcards okay.
  1204. `u':   Like `i', but the word is lower-cased first.
  1205. `m':   Like `i', but allows one to include dictionary completion information.
  1206. `C-l':  redraws screen
  1207. `C-r':  recursive edit
  1208. `C-z':  suspend emacs or iconify frame"
  1209.  
  1210.   (let ((help-1 (concat "[r/R]eplace word; [a/A]ccept for this session; "
  1211.             "[i]nsert into private dictionary"))
  1212.     (help-2 (concat "[l]ook a word up in alternate dictionary;  "
  1213.             "e[x/X]it;  [q]uit session"))
  1214.     (help-3 (concat "[u]ncapitalized insert into dictionary.  "
  1215.             "Type 'C-h d ispell-help' for more help")))
  1216.     (save-window-excursion
  1217.       (if ispell-help-in-bufferp
  1218.       (progn
  1219.         (ispell-overlay-window 4)
  1220.         (switch-to-buffer (get-buffer-create "*Ispell Help*"))
  1221.         (insert (concat help-1 "\n" help-2 "\n" help-3))
  1222.         (sit-for 5)
  1223.         (kill-buffer "*Ispell Help*"))
  1224.     (select-window (minibuffer-window))
  1225.     ;;(enlarge-window 2)
  1226.     (erase-buffer)
  1227.     (cond ((and (< emacs-minor-version 12)
  1228.             (string-match "Lucid" emacs-version))
  1229.            (message help-3)
  1230.            (enlarge-window 1)
  1231.            (message help-2)
  1232.            (enlarge-window 1)
  1233.            (message help-1)
  1234.            (goto-char (point-min)))
  1235.           (t
  1236.            (if (string-lessp "19" emacs-version)
  1237.            (message nil))
  1238.            (enlarge-window 2)
  1239.            (insert (concat help-1 "\n" help-2 "\n" help-3))))
  1240.     (sit-for 5)
  1241.     (erase-buffer)))))
  1242.  
  1243.  
  1244. (defun lookup-words (word &optional lookup-dict)
  1245.   "Look up word in word-list dictionary.
  1246. A `*' serves as a wild card.  If no wild cards, `look' is used if it exists.
  1247. Otherwise the variable `ispell-grep-command' contains the command used to
  1248. search for the words (usually egrep).
  1249.  
  1250. Optional second argument contains the dictionary to use; the default is
  1251. `ispell-alternate-dictionary'."
  1252.   ;; We don't use the filter for this function, rather the result is written
  1253.   ;; into a buffer.  Hence there is no need to save the filter values.
  1254.   (if (null lookup-dict)
  1255.       (setq lookup-dict ispell-alternate-dictionary))
  1256.  
  1257.   (let* ((process-connection-type ispell-use-ptys-p)
  1258.      (wild-p (string-match "\\*" word))
  1259.      (look-p (and ispell-look-p    ; Only use look for an exact match.
  1260.               (or ispell-have-new-look (not wild-p))))
  1261.      (ispell-grep-buffer (get-buffer-create "*Ispell-Temp*")) ; result buf
  1262.      (prog (if look-p ispell-look-command ispell-grep-command))
  1263.      (args (if look-p ispell-look-options ispell-grep-options))
  1264.      status results loc)
  1265.     (unwind-protect
  1266.     (save-window-excursion
  1267.       (message "Starting \"%s\" process..." (file-name-nondirectory prog))
  1268.       (set-buffer ispell-grep-buffer)
  1269.       (if look-p
  1270.           nil
  1271.         ;; convert * to .*
  1272.         (insert "^" word "$")
  1273.         (while (search-backward "*" nil t) (insert "."))
  1274.         (setq word (buffer-string))
  1275.         (erase-buffer))
  1276.       (setq status (call-process prog nil t nil args word lookup-dict))
  1277.       ;; grep returns status 1 and no output when word not found, which
  1278.       ;; is a perfectly normal thing.
  1279.       (if (stringp status)
  1280.           (setq results (cons (format "error: %s exited with signal %s"
  1281.                       (file-name-nondirectory prog) status)
  1282.                   results))
  1283.         ;; else collect words into `results' in FIFO order
  1284.         (goto-char (point-max))
  1285.         ;; assure we've ended with \n
  1286.         (or (bobp) (= (preceding-char) ?\n) (insert ?\n))
  1287.         (while (not (bobp))
  1288.           (setq loc (point))
  1289.           (forward-line -1)
  1290.           (setq results (cons (buffer-substring (point) (1- loc))
  1291.                   results)))))
  1292.       ;; protected
  1293.       (kill-buffer ispell-grep-buffer)
  1294.       (if (and results (string-match ".+: " (car results)))
  1295.       (error "%s error: %s" ispell-grep-command (car results))))
  1296.     results))
  1297.  
  1298.  
  1299. ;;; "ispell-filter" is a list of output lines from the generating function.
  1300. ;;;   Each full line (ending with \n) is a separate item on the list.
  1301. ;;; "output" can contain multiple lines, part of a line, or both.
  1302. ;;; "start" and "end" are used to keep bounds on lines when "output" contains
  1303. ;;;   multiple lines.
  1304. ;;; "ispell-filter-continue" is true when we have received only part of a
  1305. ;;;   line as output from a generating function ("output" did not end with \n)
  1306. ;;; NOTE THAT THIS FUNCTION WILL FAIL IF THE PROCESS OUTPUT DOESNT END WITH \n!
  1307. ;;;   This is the case when a process dies or fails. The default behavior
  1308. ;;;   in this case treats the next input received as fresh input.
  1309.  
  1310. (defun ispell-filter (process output)
  1311.   "Output filter function for ispell, grep, and look."
  1312.   (let ((start 0)
  1313.     (continue t)
  1314.     end)
  1315.     (while continue
  1316.       (setq end (string-match "\n" output start)) ; get text up to the newline.
  1317.       ;; If we get out of sync and ispell-filter-continue is asserted when we
  1318.       ;; are not continuing, treat the next item as a separate list.  When
  1319.       ;; ispell-filter-continue is asserted, ispell-filter *should* always be a
  1320.       ;; list!
  1321.  
  1322.       ;; Continue with same line (item)?
  1323.       (if (and ispell-filter-continue ispell-filter (listp ispell-filter))
  1324.       ;; Yes.  Add it to the prev item
  1325.       (setcar ispell-filter
  1326.           (concat (car ispell-filter) (substring output start end)))
  1327.     ;; No. This is a new line and item.
  1328.     (setq ispell-filter
  1329.           (cons (substring output start end) ispell-filter)))
  1330.       (if (null end)
  1331.       ;; We've completed reading the output, but didn't finish the line.
  1332.       (setq ispell-filter-continue t continue nil)
  1333.     ;; skip over newline, this line complete.
  1334.     (setq ispell-filter-continue nil end (1+ end))
  1335.     (if (= end (length output))    ; No more lines in output
  1336.         (setq continue nil)        ;  so we can exit the filter.
  1337.       (setq start end))))))        ; else move start to next line of input
  1338.  
  1339.  
  1340. ;;; This function destroys the mark location if it is in the word being
  1341. ;;; highlighted.
  1342. (defun ispell-highlight-spelling-error-generic (start end &optional highlight)
  1343.   "Highlight the word from START to END with a kludge using `inverse-video'.
  1344. When the optional third arg HIGHLIGHT is set, the word is highlighted;
  1345. otherwise it is displayed normally."
  1346.   (let ((modified (buffer-modified-p))    ; don't allow this fn to modify buffer
  1347.     (buffer-read-only nil)        ; Allow highlighting read-only buffers.
  1348.     (text (buffer-substring start end)) ; Save highlight region
  1349.     (inhibit-quit t)        ; inhibit interrupt processing here.
  1350.     (buffer-undo-list t))        ; don't clutter the undo list.
  1351.     (delete-region start end)
  1352.     (insert-char ?  (- end start))    ; mimimize amount of redisplay
  1353.     (sit-for 0)                ; update display
  1354.     (if highlight (setq inverse-video (not inverse-video))) ; toggle video
  1355.     (delete-region start end)        ; delete whitespace
  1356.     (insert text)            ; insert text in inverse video.
  1357.     (sit-for 0)                ; update display showing inverse video.
  1358.     (if highlight (setq inverse-video (not inverse-video))) ; toggle video
  1359.     (set-buffer-modified-p modified)))    ; don't modify if flag not set.
  1360.  
  1361.  
  1362. (defun ispell-highlight-spelling-error-lucid (start end &optional highlight)
  1363.   "Highlight the word from START to END using `isearch-highlight'.
  1364. When the optional third arg HIGHLIGHT is set, the word is highlighted,
  1365. otherwise it is displayed normally."
  1366.   (if highlight
  1367.       (isearch-highlight start end)
  1368.     (isearch-dehighlight t))
  1369.   ;;(sit-for 0)
  1370.   )
  1371.  
  1372.  
  1373. (defun ispell-highlight-spelling-error-overlay (start end &optional highlight)
  1374.   "Highlight the word from START to END using overlays.
  1375. When the optional third arg HIGHLIGHT is set, the word is highlighted
  1376. otherwise it is displayed normally.
  1377.  
  1378. The variable `ispell-highlight-face' selects the face to use for highlighting."
  1379.   (if highlight
  1380.       (progn
  1381.     (setq ispell-overlay (make-overlay start end))
  1382.     (overlay-put ispell-overlay 'face ispell-highlight-face))
  1383.     (delete-overlay ispell-overlay)))
  1384.  
  1385.  
  1386. (defun ispell-highlight-spelling-error (start end &optional highlight)
  1387.   (cond
  1388.    ((string-match "Lucid" emacs-version)
  1389.     (ispell-highlight-spelling-error-lucid start end highlight))
  1390.    ((and (string-lessp "19" emacs-version)
  1391.      (featurep 'faces) window-system)
  1392.     (ispell-highlight-spelling-error-overlay start end highlight))
  1393.    (t (ispell-highlight-spelling-error-generic start end highlight))))
  1394.  
  1395.  
  1396. (defun ispell-overlay-window (height)
  1397.   "Create a window covering the top HEIGHT lines of the current window.
  1398. Ensure that the line above point is still visible but otherwise avoid
  1399. scrolling the current window.  Leave the new window selected."
  1400.   (save-excursion
  1401.     (let ((oldot (save-excursion (forward-line -1) (point)))
  1402.       (top (save-excursion (move-to-window-line height) (point))))
  1403.       ;; If line above old point (line starting at olddot) would be
  1404.       ;; hidden by new window, scroll it to just below new win
  1405.       ;; otherwise set top line of other win so it doesn't scroll.
  1406.       (if (< oldot top) (setq top oldot))
  1407.       ;; NB: Lemacs 19.9 bug: If a window of size N (N includes the mode
  1408.       ;; line) is demanded, the last line is not visible.
  1409.       ;; At least this happens on AIX 3.2, lemacs w/ Motif, font 9x15.
  1410.       ;; So we increment the height for this case.
  1411.       (if (string-match "19\.9.*Lucid" (emacs-version))
  1412.       (setq height (1+ height)))
  1413.       (split-window nil height)
  1414.       (set-window-start (next-window) top))))
  1415.  
  1416.  
  1417. ;;; Should we add a compound word match return value?
  1418. (defun ispell-parse-output (output)
  1419.   "Parse the OUTPUT string from Ispell and return:
  1420. 1: t for an exact match.
  1421. 2: A string containing the root word for a match via suffix removal.
  1422. 3: A list of possible correct spellings of the format:
  1423.    '(\"ORIGINAL-WORD\" OFFSET MISS-LIST GUESS-LIST)
  1424.    ORIGINAL-WORD is a string of the possibly misspelled word.
  1425.    OFFSET is an integer giving the line offset of the word.
  1426.    MISS-LIST and GUESS-LIST are possibly null lists of guesses and misses."
  1427.   (cond
  1428.    ((string= output "") t)        ; for startup with pipes...
  1429.    ((string= output "*") t)        ; exact match
  1430.    ((string= output "-") t)             ; compound word match
  1431.    ((string= (substring output 0 1) "+") ; found cuz of root word
  1432.     (substring output 2))        ; return root word
  1433.    (t                    ; need to process &, ?, and #'s
  1434.     (let ((type (substring output 0 1))    ; &, ?, or #
  1435.       (original-word (substring output 2 (string-match " " output 2)))
  1436.       (cur-count 0)            ; contains number of misses + guesses
  1437.       count miss-list guess-list offset)
  1438.       (setq output (substring output (match-end 0))) ; skip over misspelling
  1439.       (if (string= type "#")
  1440.       (setq count 0)        ; no misses for type #
  1441.     (setq count (string-to-int output) ; get number of misses.
  1442.           output (substring output (1+ (string-match " " output 1)))))
  1443.       (setq offset (string-to-int output))
  1444.       (if (string= type "#")        ; No miss or guess list.
  1445.       (setq output nil)
  1446.     (setq output (substring output (1+ (string-match " " output 1)))))
  1447.       (while output
  1448.     (let ((end (string-match ", \\|\\($\\)" output))) ; end of miss/guess.
  1449.       (setq cur-count (1+ cur-count))
  1450.       (if (> cur-count count)
  1451.           (setq guess-list (cons (substring output 0 end) guess-list))
  1452.         (setq miss-list (cons (substring output 0 end) miss-list)))
  1453.       (if (match-end 1)        ; True only when at end of line.
  1454.           (setq output nil)        ; no more misses or guesses
  1455.         (setq output (substring output (+ end 2))))))
  1456.       (list original-word offset miss-list guess-list)))))
  1457.  
  1458.  
  1459. (defun check-ispell-version ()
  1460.   ;; This is a little wasteful as we actually launch ispell twice: once
  1461.   ;; to make sure it's the right version, and once for real.  But people
  1462.   ;; get confused by version mismatches *all* the time (and I've got the
  1463.   ;; email to prove it) so I think this is worthwhile.  And the -v[ersion]
  1464.   ;; option is the only way I can think of to do this that works with
  1465.   ;; all versions, since versions earlier than 3.0.09 didn't identify
  1466.   ;; themselves on startup.
  1467.   (save-excursion
  1468.     (set-buffer (get-buffer-create " *ispell-tmp*"))
  1469.     (erase-buffer)
  1470.     (let ((status (call-process ispell-program-name nil t nil "-v"))
  1471.       (case-fold-search t))
  1472.       (goto-char (point-min))
  1473.       (if (not (memq status '(0 nil)))
  1474.       (error "%s exited with %s %s" ispell-program-name
  1475.          (if (stringp status) "signal" "code") status))
  1476.       (if (not (re-search-forward
  1477.         (concat "\\b\\("
  1478.             (regexp-quote (car ispell-required-version))
  1479.             "\\)\\([0-9]*\\)\\b")
  1480.         nil t))
  1481.       (error
  1482.        "%s version %s* is required: try renaming ispell4.el to ispell.el"
  1483.        ispell-program-name (car ispell-required-version))
  1484.     ;; check that it is the correct version.
  1485.     (if (< (car (read-from-string (buffer-substring
  1486.                        (match-beginning 2) (match-end 2))))
  1487.            (car (cdr ispell-required-version)))
  1488.         (setq ispell-offset 0)))
  1489.       (kill-buffer (current-buffer)))))
  1490.  
  1491.  
  1492. (defun ispell-init-process ()
  1493.   "Check status of Ispell process and start if necessary."
  1494.   (if (and ispell-process
  1495.        (eq (process-status ispell-process) 'run)
  1496.        ;; If we're using a personal dictionary, assure
  1497.        ;; we're in the same default directory!
  1498.        (or (not ispell-personal-dictionary)
  1499.            (equal ispell-process-directory default-directory)))
  1500.       (setq ispell-filter nil ispell-filter-continue nil)
  1501.     ;; may need to restart to select new personal dictionary.
  1502.     (ispell-kill-ispell t)
  1503.     (message "Starting new Ispell process...")
  1504.     (sit-for 0)
  1505.     (check-ispell-version)
  1506.     (setq ispell-process
  1507.       (let ((process-connection-type ispell-use-ptys-p))
  1508.         (apply 'start-process
  1509.            "ispell" nil ispell-program-name
  1510.            "-a"            ; accept single input lines
  1511.            "-m"            ; make root/affix combos not in dict
  1512.            (let (args)
  1513.              ;; Local dictionary becomes the global dictionary in use.
  1514.              (if ispell-local-dictionary
  1515.              (setq ispell-dictionary ispell-local-dictionary))
  1516.              (setq args (ispell-get-ispell-args))
  1517.              (if ispell-dictionary ; use specified dictionary
  1518.              (setq args
  1519.                    (append (list "-d" ispell-dictionary) args)))
  1520.              (if ispell-personal-dictionary ; use specified pers dict
  1521.              (setq args
  1522.                    (append args
  1523.                        (list "-p"
  1524.                          (expand-file-name
  1525.                           ispell-personal-dictionary)))))
  1526.              (setq args (append args ispell-extra-args))
  1527.              args)))
  1528.       ispell-filter nil
  1529.       ispell-filter-continue nil
  1530.       ispell-process-directory default-directory)
  1531.     (set-process-filter ispell-process 'ispell-filter)
  1532.     (accept-process-output ispell-process) ; Get version ID line
  1533.     (cond ((null ispell-filter)
  1534.        (error "%s did not output version line" ispell-program-name))
  1535.       ((and (null (cdr ispell-filter))
  1536.         (stringp (car ispell-filter))
  1537.         (string-match "^@(#) " (car ispell-filter)))
  1538.        ;; got the version line as expected (we already know it's the right
  1539.        ;; version, so don't bother checking again.)
  1540.        nil)
  1541.       (t
  1542.        ;; Otherwise, it must be an error message.  Show the user.
  1543.        ;; But first wait to see if some more output is going to arrive.
  1544.        ;; Otherwise we get cool errors like "Can't open ".
  1545.        (sleep-for 1)
  1546.        (accept-process-output)
  1547.        (error "%s" (mapconcat 'identity ispell-filter "\n"))))
  1548.     (setq ispell-filter nil)        ; Discard version ID line
  1549.     (let ((extended-char-mode (ispell-get-extended-character-mode)))
  1550.       (if extended-char-mode
  1551.       (process-send-string ispell-process
  1552.                    (concat extended-char-mode "\n"))))
  1553.     (process-kill-without-query ispell-process)))
  1554.  
  1555. ;;;###autoload
  1556. (defun ispell-kill-ispell (&optional no-error)
  1557.   "Kill current Ispell process (so that you may start a fresh one).
  1558. With NO-ERROR, just return non-nil if there was no Ispell running."
  1559.   (interactive)
  1560.   (if (not (and ispell-process
  1561.         (eq (process-status ispell-process) 'run)))
  1562.       (or no-error
  1563.       (error "There is no ispell process running!"))
  1564.     (kill-process ispell-process)
  1565.     (setq ispell-process nil)
  1566.     (message "Ispell process killed")
  1567.     nil))
  1568.  
  1569.  
  1570. ;;; ispell-change-dictionary is set in some people's hooks.  Maybe it should
  1571. ;;;  call ispell-init-process rather than wait for a spell checking command?
  1572.  
  1573. ;;;###autoload
  1574. (defun ispell-change-dictionary (dict &optional arg)
  1575.   "Change `ispell-dictionary' (q.v.) and kill old Ispell process.
  1576. A new one will be started as soon as necessary.
  1577.  
  1578. By just answering RET you can find out what the current dictionary is.
  1579.  
  1580. With prefix argument, set the default directory."
  1581.   (interactive
  1582.    (list (completing-read
  1583.       "Use new dictionary (RET for current, SPC to complete): "
  1584.       (cons (cons "default" nil) ispell-dictionary-alist) nil t)
  1585.      current-prefix-arg))
  1586.   (if (equal dict "default") (setq dict nil))
  1587.   ;; This relies on completing-read's bug of returning "" for no match
  1588.   (cond ((equal dict "")
  1589.      (message "Using %s dictionary"
  1590.           (or ispell-local-dictionary ispell-dictionary "default")))
  1591.     ((and (equal dict ispell-dictionary)
  1592.           (or (null ispell-local-dictionary)
  1593.           (equal dict ispell-local-dictionary)))
  1594.      ;; Specified dictionary is the default already.  No-op
  1595.      (and (interactive-p)
  1596.           (message "No change, using %s dictionary" (or dict "default"))))
  1597.     (t                ; reset dictionary!
  1598.      (if (assoc dict ispell-dictionary-alist)
  1599.          (progn
  1600.            (if (or arg (null dict))    ; set default dictionary
  1601.            (setq ispell-dictionary dict))
  1602.            (if (null arg)        ; set local dictionary
  1603.            (setq ispell-local-dictionary dict)))
  1604.        (error "Illegal dictionary: %s" dict))
  1605.      (ispell-kill-ispell t)
  1606.      (message "(Next %sIspell command will use %s dictionary)"
  1607.           (cond ((equal ispell-local-dictionary ispell-dictionary)
  1608.              "")
  1609.             (arg "global ")
  1610.             (t "local "))
  1611.           (or (if (or (equal ispell-local-dictionary ispell-dictionary)
  1612.                   (null arg))
  1613.               ispell-local-dictionary
  1614.             ispell-dictionary)
  1615.               "default")))))
  1616.  
  1617.  
  1618. ;;; Spelling of comments are checked when ispell-check-comments is non-nil.
  1619.  
  1620. ;;;###autoload
  1621. (defun ispell-region (reg-start reg-end)
  1622.   "Interactively check a region for spelling errors."
  1623.   (interactive "r")            ; Don't flag errors on read-only bufs.
  1624.   (ispell-accept-buffer-local-defs)    ; set up dictionary, local words, etc.
  1625.   (unwind-protect
  1626.       (save-excursion
  1627.     (message "Spell checking %s using %s dictionary..."
  1628.          (if (and (= reg-start (point-min)) (= reg-end (point-max)))
  1629.              (buffer-name) "region")
  1630.          (or ispell-dictionary "default"))
  1631.     ;; Returns cursor to original location.
  1632.     (save-window-excursion
  1633.       (goto-char reg-start)
  1634.       (let ((transient-mark-mode nil)
  1635.         ref-type)
  1636.         (while (and (not ispell-quit) (< (point) reg-end))
  1637.           (let ((start (point))
  1638.             (offset-change 0)
  1639.             (end (save-excursion (end-of-line) (min (point) reg-end)))
  1640.             (ispell-casechars (ispell-get-casechars))
  1641.             string)
  1642.         (cond            ; LOOK AT THIS LINE AND SKIP OR PROCESS
  1643.          ((eolp)        ; END OF LINE, just go to next line.
  1644.           (forward-char 1))
  1645.          ((and (null ispell-check-comments) ; SKIPPING COMMENTS
  1646.                comment-start    ; skip comments that start on the line.
  1647.                (search-forward comment-start end t)) ; or found here.
  1648.           (if (= (- (point) start) (length comment-start))
  1649.               ;; comment starts the line.  Skip entire line or region
  1650.               (if (string= "" comment-end) ; skip to next line
  1651.               (beginning-of-line 2)    ; or jump to comment end.
  1652.             (search-forward comment-end reg-end 'limit))
  1653.             ;; Comment later in line.  Check spelling before comment.
  1654.             (let ((limit (- (point) (length comment-start))))
  1655.               (goto-char (1- limit))
  1656.               (if (looking-at "\\\\") ; "quoted" comment, don't skip
  1657.               ;; quoted comment.  Skip over comment-start
  1658.               (if (= start (1- limit))
  1659.                   (setq limit (+ limit (length comment-start)))
  1660.                 (setq limit (1- limit))))
  1661.               (goto-char start)
  1662.               ;; Only check when "casechars" or math before comment
  1663.               (if (or (re-search-forward ispell-casechars limit t)
  1664.                   (re-search-forward "[][()$]" limit t))
  1665.               (setq string
  1666.                 (concat "^" (buffer-substring start limit)
  1667.                     "\n")
  1668.                 offset-change (- offset-change ispell-offset)))
  1669.               (goto-char limit))))
  1670.          ((looking-at "[---#@*+!%~^]") ; SKIP SPECIAL ISPELL CHARACTERS
  1671.           (forward-char 1))
  1672.          ((or (and ispell-skip-tib ; SKIP TIB OR SGML REFERENCES!
  1673.                (re-search-forward ispell-tib-ref-beginning end t)
  1674.                (setq ref-type 'tib))
  1675.               (and ispell-skip-sgml-tags
  1676.                (search-forward "<" end t)
  1677.                (setq ref-type 'sgml)))
  1678.           (if (or (and (eq 'tib ref-type) ; tib tag is 2 chars.
  1679.                    (= (- (point) 2) start))
  1680.               (and (eq 'sgml ref-type) ; sgml tag is 1 char.
  1681.                    (= (- (point) 1) start)))
  1682.               ;; Skip to end of reference, not necessarily on this line
  1683.               ;; Return an error if tib/sgml reference not found
  1684.               (if (or
  1685.                (and
  1686.                 (eq 'tib ref-type)
  1687.                 (not
  1688.                  (re-search-forward ispell-tib-ref-end reg-end t)))
  1689.                (and (eq 'sgml ref-type)
  1690.                 (not (search-forward ">" reg-end t))))
  1691.               (progn
  1692.                 (ispell-pdict-save ispell-silently-savep)
  1693.                 (ding)
  1694.                 (message
  1695.                  (concat
  1696.                   "Open tib or SGML reference.  Fix buffer or set "
  1697.                   (if (eq 'tib ref-type)
  1698.                   "ispell-skip-tib"
  1699.                 "ispell-skip-sgml-tags")
  1700.                   " to nil"))
  1701.                 ;; keep cursor at error location
  1702.                 (setq ispell-quit (- (point) 2))))
  1703.             ;; Check spelling between reference and start of the line.
  1704.             (let ((limit (- (point) (if (eq 'tib ref-type) 2 1))))
  1705.               (goto-char start)
  1706.               (if (or (re-search-forward ispell-casechars limit t)
  1707.                   (re-search-forward "[][()$]" limit t))
  1708.               (setq string
  1709.                 (concat "^" (buffer-substring start limit)
  1710.                     "\n")
  1711.                 offset-change (- offset-change ispell-offset)))
  1712.               (goto-char limit))))
  1713.          ((or (re-search-forward ispell-casechars end t) ; TEXT EXISTS
  1714.               (re-search-forward "[][()$]" end t)) ; or MATH COMMANDS
  1715.           (setq string (concat "^" (buffer-substring start end) "\n")
  1716.             offset-change (- offset-change ispell-offset))
  1717.           (goto-char end))
  1718.          (t (beginning-of-line 2))) ; EMPTY LINE, skip it.
  1719.  
  1720.         (setq end (point))    ; "end" tracks end of region to check.
  1721.  
  1722.         (if string        ; there is something to spell!
  1723.             (let (poss)
  1724.               ;; send string to spell process and get input.
  1725.               (process-send-string ispell-process string)
  1726.               (while (progn
  1727.                    (accept-process-output ispell-process)
  1728.                    ;; Last item of output contains a blank line.
  1729.                    (not (string= "" (car ispell-filter)))))
  1730.               ;; parse all inputs from the stream one word at a time.
  1731.               ;; Place in FIFO order and remove the blank item.
  1732.               (setq ispell-filter (nreverse (cdr ispell-filter)))
  1733.               (while (and (not ispell-quit) ispell-filter)
  1734.             (setq poss (ispell-parse-output (car ispell-filter)))
  1735.             (if (listp poss) ; spelling error occurred.
  1736.                 (let* ((word-start (+ start offset-change
  1737.                           (car (cdr poss))))
  1738.                    (word-end (+ word-start
  1739.                         (length (car poss))))
  1740.                    replace)
  1741.                   (goto-char word-start)
  1742.                   ;; Adjust the horizontal scroll & point
  1743.                   (ispell-horiz-scroll)
  1744.                   (goto-char word-end)
  1745.                   (ispell-horiz-scroll)
  1746.                   (goto-char word-start)
  1747.                   (ispell-horiz-scroll)
  1748.                   (if (/= word-end
  1749.                       (progn
  1750.                     (search-forward (car poss) word-end t)
  1751.                     (point)))
  1752.                   ;; This occurs due to filter pipe problems
  1753.                   (error
  1754.                    (concat "Ispell misalignment: word "
  1755.                        "`%s' point %d; please retry")
  1756.                    (car poss) word-start))
  1757.                   (if ispell-keep-choices-win
  1758.                   (setq replace
  1759.                     (ispell-command-loop
  1760.                      (car (cdr (cdr poss)))
  1761.                      (car (cdr (cdr (cdr poss))))
  1762.                      (car poss) word-start word-end))
  1763.                 (save-window-excursion
  1764.                   (setq replace
  1765.                     (ispell-command-loop
  1766.                      (car (cdr (cdr poss)))
  1767.                      (car (cdr (cdr (cdr poss))))
  1768.                      (car poss) word-start word-end))))
  1769.                   (cond
  1770.                    ((and replace (listp replace))
  1771.                 ;; REPLACEMENT WORD entered.  Recheck line
  1772.                 ;; starting with the replacement word.
  1773.                 (setq ispell-filter nil
  1774.                       string (buffer-substring word-start
  1775.                                    word-end))
  1776.                 (let ((change (- (length (car replace))
  1777.                          (length (car poss)))))
  1778.                   ;; adjust regions
  1779.                   (setq reg-end (+ reg-end change)
  1780.                     offset-change (+ offset-change
  1781.                              change)))
  1782.                 (if (not (equal (car replace) (car poss)))
  1783.                     (progn
  1784.                       (delete-region word-start word-end)
  1785.                       (insert (car replace))))
  1786.                 ;; I only need to recheck typed-in replacements
  1787.                 (if (not (eq 'query-replace
  1788.                          (car (cdr replace))))
  1789.                     (backward-char (length (car replace))))
  1790.                 (setq end (point)) ; reposition for recheck
  1791.                 ;; when second arg exists, query-replace, saving regions
  1792.                 (if (car (cdr replace))
  1793.                     (unwind-protect
  1794.                     (save-window-excursion
  1795.                       (set-marker
  1796.                        ispell-query-replace-marker reg-end)
  1797.                       ;; Assume case-replace &
  1798.                       ;; case-fold-search correct?
  1799.                       (query-replace string (car replace)
  1800.                              t))
  1801.                       (setq reg-end
  1802.                         (marker-position
  1803.                          ispell-query-replace-marker))
  1804.                       (set-marker ispell-query-replace-marker
  1805.                           nil))))
  1806.                    ((or (null replace)
  1807.                     (equal 0 replace)) ; ACCEPT/INSERT
  1808.                 (if (equal 0 replace) ; BUFFER-LOCAL DICT ADD
  1809.                     (setq reg-end
  1810.                       (ispell-add-per-file-word-list
  1811.                        (car poss) reg-end)))
  1812.                 ;; This avoids pointing out the word that was
  1813.                 ;; just accepted (via 'i' or 'a') if it follows
  1814.                 ;; on the same line.
  1815.                 ;; Redo check following the accepted word.
  1816.                 (if (and ispell-pdict-modified-p
  1817.                      (listp ispell-pdict-modified-p))
  1818.                     ;; Word accepted.  Recheck line.
  1819.                     (setq ispell-pdict-modified-p ; update flag
  1820.                       (car ispell-pdict-modified-p)
  1821.                       ispell-filter nil ; discontinue check
  1822.                       end word-start))) ; reposition loc.
  1823.                    (replace    ; STRING REPLACEMENT for this word.
  1824.                 (delete-region word-start word-end)
  1825.                 (insert replace)
  1826.                 (let ((change (- (length replace)
  1827.                          (length (car poss)))))
  1828.                   (setq reg-end (+ reg-end change)
  1829.                     offset-change (+ offset-change change)
  1830.                     end (+ end change)))))
  1831.                   (if (not ispell-quit)
  1832.                   (message
  1833.                    (concat "Continuing spelling check using "
  1834.                        (or ispell-dictionary "default")
  1835.                        " dictionary...")))
  1836.                   (sit-for 0)))
  1837.             ;; finished with line!
  1838.             (setq ispell-filter (cdr ispell-filter)))))
  1839.         (goto-char end)))))
  1840.     (not ispell-quit))
  1841.     ;; protected
  1842.     (if (get-buffer ispell-choices-buffer)
  1843.     (kill-buffer ispell-choices-buffer))
  1844.     (if ispell-quit
  1845.     (progn
  1846.       ;; preserve or clear the region for ispell-continue.
  1847.       (if (not (numberp ispell-quit))
  1848.           (set-marker ispell-region-end nil)
  1849.         ;; Enable ispell-continue.
  1850.         (set-marker ispell-region-end reg-end)
  1851.         (goto-char ispell-quit))
  1852.       ;; Check for aborting
  1853.       (if (and ispell-checking-message (numberp ispell-quit))
  1854.           (progn
  1855.         (setq ispell-quit nil)
  1856.         (error "Message send aborted.")))
  1857.       (setq ispell-quit nil))
  1858.       (set-marker ispell-region-end nil)
  1859.       ;; Only save if successful exit.
  1860.       (ispell-pdict-save ispell-silently-savep)
  1861.       (message "Spell-checking done"))))
  1862.  
  1863.  
  1864.  
  1865. ;;;###autoload
  1866. (defun ispell-buffer ()
  1867.   "Check the current buffer for spelling errors interactively."
  1868.   (interactive)
  1869.   (ispell-region (point-min) (point-max)))
  1870.  
  1871.  
  1872. ;;;###autoload
  1873. (defun ispell-continue ()
  1874.   (interactive)
  1875.   "Continue a spelling session after making some changes."
  1876.   (if (not (marker-position ispell-region-end))
  1877.       (message "No session to continue.  Use 'X' command when checking!")
  1878.     (if (not (equal (marker-buffer ispell-region-end) (current-buffer)))
  1879.     (message "Must continue ispell from buffer %s"
  1880.          (buffer-name (marker-buffer ispell-region-end)))
  1881.       (ispell-region (point) (marker-position ispell-region-end)))))
  1882.  
  1883.  
  1884. ;;; Horizontal scrolling
  1885. (defun ispell-horiz-scroll ()
  1886.   "Places point within the horizontal visibility of its window area."
  1887.   (if truncate-lines            ; display truncating lines?
  1888.       ;; See if display needs to be scrolled.
  1889.       (let ((column (- (current-column) (max (window-hscroll) 1))))
  1890.     (if (and (< column 0) (> (window-hscroll) 0))
  1891.         (scroll-right (max (- column) 10))
  1892.       (if (>= column (- (window-width) 2))
  1893.           (scroll-left (max (- column (window-width) -3) 10)))))))
  1894.  
  1895.  
  1896. ;;; Interactive word completion.
  1897. ;;; Forces "previous-word" processing.  Do we want to make this selectable?
  1898.  
  1899. ;;;###autoload
  1900. (defun ispell-complete-word (&optional interior-frag)
  1901.   "Look up word before or under point in dictionary (see lookup-words command)
  1902. and try to complete it.  If optional INTERIOR-FRAG is non-nil then the word
  1903. may be a character sequence inside of a word.
  1904.  
  1905. Standard ispell choices are then available."
  1906.   (interactive "P")
  1907.   (let ((cursor-location (point))
  1908.     case-fold-search
  1909.     (word (ispell-get-word nil "\\*")) ; force "previous-word" processing.
  1910.     start end possibilities replacement)
  1911.     (setq start (car (cdr word))
  1912.       end (car (cdr (cdr word)))
  1913.       word (car word)
  1914.       possibilities
  1915.       (or (string= word "")        ; Will give you every word
  1916.           (lookup-words (concat (if interior-frag "*") word "*")
  1917.                 ispell-complete-word-dict)))
  1918.     (cond ((eq possibilities t)
  1919.        (message "No word to complete"))
  1920.       ((null possibilities)
  1921.        (message "No match for \"%s\"" word))
  1922.       (t                ; There is a modification...
  1923.        (cond            ; Try and respect case of word.
  1924.         ((string-match "^[^A-Z]+$" word)
  1925.          (setq possibilities (mapcar 'downcase possibilities)))
  1926.         ((string-match "^[^a-z]+$" word)
  1927.          (setq possibilities (mapcar 'upcase possibilities)))
  1928.         ((string-match "^[A-Z]" word)
  1929.          (setq possibilities (mapcar 'capitalize possibilities))))
  1930.        (save-window-excursion
  1931.          (setq replacement
  1932.            (ispell-command-loop possibilities nil word start end)))
  1933.        (cond
  1934.         ((equal 0 replacement)    ; BUFFER-LOCAL ADDITION
  1935.          (ispell-add-per-file-word-list word))
  1936.         (replacement        ; REPLACEMENT WORD
  1937.          (delete-region start end)
  1938.          (setq word (if (atom replacement) replacement (car replacement))
  1939.            cursor-location (+ (- (length word) (- end start))
  1940.                       cursor-location))
  1941.          (insert word)
  1942.          (if (not (atom replacement)) ; recheck spelling of replacement.
  1943.          (progn
  1944.            (goto-char cursor-location)
  1945.            (ispell-word nil t)))))
  1946.        (if (get-buffer ispell-choices-buffer)
  1947.            (kill-buffer ispell-choices-buffer))))
  1948.     (ispell-pdict-save ispell-silently-savep)
  1949.     (goto-char cursor-location)))
  1950.  
  1951.  
  1952. ;;;###autoload
  1953. (defun ispell-complete-word-interior-frag ()
  1954.   "Completes word matching character sequence inside a word."
  1955.   (interactive)
  1956.   (ispell-complete-word t))
  1957.  
  1958.  
  1959. ;;; **********************************************************************
  1960. ;;;             Ispell Minor Mode
  1961. ;;; **********************************************************************
  1962.  
  1963. (defvar ispell-minor-mode nil
  1964.   "Non-nil if Ispell minor mode is enabled.")
  1965. ;; Variable indicating that ispell minor mode is active.
  1966. (make-variable-buffer-local 'ispell-minor-mode)
  1967.  
  1968. (or (assq 'ispell-minor-mode minor-mode-alist)
  1969.     (setq minor-mode-alist
  1970.           (cons '(ispell-minor-mode " Spell") minor-mode-alist)))
  1971.  
  1972. (defvar ispell-minor-keymap
  1973.   (let ((map (make-sparse-keymap)))
  1974.     (define-key map " " 'ispell-minor-check)
  1975.     (define-key map "\r" 'ispell-minor-check)
  1976.     map)
  1977.   "Keymap used for Ispell minor mode.")
  1978.  
  1979. (or (not (boundp 'minor-mode-map-alist))
  1980.     (assoc 'ispell-minor-mode minor-mode-map-alist)
  1981.     (setq minor-mode-map-alist
  1982.           (cons (cons 'ispell-minor-mode ispell-minor-keymap)
  1983.                 minor-mode-map-alist)))
  1984.  
  1985. ;;;###autoload
  1986. (defun ispell-minor-mode (&optional arg)
  1987.   "Toggle Ispell minor mode.
  1988. With prefix arg, turn Ispell minor mode on iff arg is positive.
  1989.  
  1990. In Ispell minor mode, pressing SPC or RET
  1991. warns you if the previous word is incorrectly spelled."
  1992.   (interactive "P")
  1993.   (setq ispell-minor-mode
  1994.     (not (or (and (null arg) ispell-minor-mode)
  1995.          (<= (prefix-numeric-value arg) 0))))
  1996.   (set-buffer-modified-p (buffer-modified-p)))
  1997.  
  1998. (defun ispell-minor-check ()
  1999.   ;; Check previous word then continue with the normal binding of this key.
  2000.   (interactive "*")
  2001.   (let ((ispell-minor-mode nil)
  2002.     (ispell-check-only t))
  2003.     (save-restriction
  2004.       (narrow-to-region (point-min) (point))
  2005.       (ispell-word nil t))
  2006.     (call-interactively (key-binding (this-command-keys)))))
  2007.  
  2008.  
  2009. ;;; **********************************************************************
  2010. ;;;             Ispell Message
  2011. ;;; **********************************************************************
  2012. ;;; Original from D. Quinlan, E. Bradford, A. Albert, and M. Ernst
  2013.  
  2014.  
  2015. (defvar ispell-message-text-end
  2016.   (mapconcat (function identity)
  2017.          '(
  2018.            ;; Matches postscript files.
  2019.            "^%!PS-Adobe-[23].0"
  2020.            ;; Matches uuencoded text
  2021.            "^begin [0-9][0-9][0-9] .*\nM.*\nM.*\nM"
  2022.            ;; Matches shell files (esp. auto-decoding)
  2023.            "^#! /bin/[ck]?sh"
  2024.            ;; Matches context difference listing
  2025.            "\\(diff -c .*\\)?\n\\*\\*\\* .*\n--- .*\n\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*"
  2026.            ;; Matches "----------------- cut here"
  2027.            "^[-=_]+\\s ?cut here")
  2028.          "\\|")
  2029.   "*End of text which will be checked in ispell-message.
  2030. If it is a string, limit at first occurrence of that regular expression.
  2031. Otherwise, it must be a function which is called to get the limit.")
  2032.  
  2033.  
  2034. ;;;###autoload
  2035. (defun ispell-message ()
  2036.   "Check the spelling of a mail message or news post.
  2037. Don't check spelling of message headers except the Subject field.
  2038. Don't check included messages.
  2039.  
  2040. To abort spell checking of a message REGION and send the message anyway,
  2041. use the `x' or `q' command.  (Any subsequent regions will be checked.)
  2042. The `X' command aborts the message send so that you can edit the buffer.
  2043.  
  2044. To spell-check whenever a message is sent, include the appropriate lines
  2045. in your .emacs file:
  2046.    (add-hook 'news-inews-hook 'ispell-message)
  2047.    (add-hook 'mail-send-hook  'ispell-message)
  2048.    (add-hook 'mh-before-send-letter-hook 'ispell-message)
  2049.  
  2050. You can bind this to the key C-c i in GNUS or mail by adding to
  2051. `news-reply-mode-hook' or `mail-mode-hook' the following lambda expression:
  2052.    (function (lambda () (local-set-key \"\\C-ci\" 'ispell-message)))"
  2053.   (interactive)
  2054.   (save-excursion
  2055.     (goto-char (point-min))
  2056.     (let* ((internal-messagep (save-excursion
  2057.                 (re-search-forward
  2058.                  (concat "^"
  2059.                      (regexp-quote mail-header-separator)
  2060.                      "$")
  2061.                  nil t)))
  2062.        (limit (copy-marker
  2063.            (cond
  2064.             ((not ispell-message-text-end) (point-max))
  2065.             ((char-or-string-p ispell-message-text-end)
  2066.              (if (re-search-forward ispell-message-text-end nil t)
  2067.              (match-beginning 0)
  2068.                (point-max)))
  2069.             (t (min (point-max) (funcall ispell-message-text-end))))))
  2070.        (cite-regexp            ;Prefix of inserted text
  2071.         (cond
  2072.          ((featurep 'supercite)    ; sc 3.0
  2073.           (concat "\\(" (sc-cite-regexp) "\\)" "\\|"
  2074.               (ispell-non-empty-string sc-reference-tag-string)))
  2075.          ((featurep 'sc)        ; sc 2.3
  2076.           (concat "\\(" sc-cite-regexp "\\)" "\\|"
  2077.               (ispell-non-empty-string sc-reference-tag-string)))
  2078.          ((equal major-mode 'news-reply-mode) ;GNUS
  2079.           (concat "In article <" "\\|"
  2080.               (if mail-yank-prefix
  2081.               (ispell-non-empty-string mail-yank-prefix)
  2082.             "^   \\|^\t")))
  2083.          ((equal major-mode 'mh-letter-mode) ; mh mail message
  2084.           (ispell-non-empty-string mh-ins-buf-prefix))
  2085.          ((not internal-messagep)    ; Assume n sent us this message.
  2086.           (concat "In [a-zA-Z.]+ you write:" "\\|"
  2087.               "In <[^,;&+=]+> [^,;&+=]+ writes:" "\\|"
  2088.               " *> *"))
  2089.          ((boundp 'vm-included-text-prefix) ; VM mail message
  2090.           (concat "[^,;&+=]+ writes:" "\\|"
  2091.               (ispell-non-empty-string vm-included-text-prefix)))
  2092.          (mail-yank-prefix        ; vanilla mail message.
  2093.           (ispell-non-empty-string mail-yank-prefix))
  2094.          (t "^   \\|^\t")))
  2095.        (cite-regexp-start (concat "^[ \t]*$\\|" cite-regexp))
  2096.        (cite-regexp-end   (concat "^\\(" cite-regexp "\\)"))
  2097.        (old-case-fold-search case-fold-search)
  2098.        (case-fold-search t)
  2099.        (ispell-checking-message t))
  2100.       (goto-char (point-min))
  2101.       ;; Skip header fields except Subject: without Re:'s
  2102.       ;;(search-forward mail-header-separator nil t)
  2103.       (while (if internal-messagep
  2104.          (< (point) internal-messagep)
  2105.            (and (looking-at "[a-zA-Z---]+:\\|\t\\| ")
  2106.             (not (eobp))))
  2107.     (if (looking-at "Subject: *")    ; Spell check new subject fields
  2108.         (progn
  2109.           (goto-char (match-end 0))
  2110.           (if (and (not (looking-at ".*Re\\>"))
  2111.                (not (looking-at "\\[")))
  2112.           (let ((case-fold-search old-case-fold-search))
  2113.             (ispell-region (point)
  2114.                    (progn
  2115.                      (end-of-line)
  2116.                      (while (looking-at "\n[ \t]")
  2117.                        (end-of-line 2))
  2118.                      (point)))))))
  2119.     (forward-line 1))
  2120.       (setq case-fold-search nil)
  2121.       ;; Skip mail header, particularly for non-english languages.
  2122.       (if (looking-at mail-header-separator)
  2123.       (forward-line 1))
  2124.       (while (< (point) limit)
  2125.     ;; Skip across text cited from other messages.
  2126.     (while (and (looking-at cite-regexp-start)
  2127.             (< (point) limit)
  2128.             (zerop (forward-line 1))))
  2129.  
  2130.     (if (< (point) limit)
  2131.         (let* ((start (point))
  2132.            ;; Check the next batch of lines that *aren't* cited.
  2133.            (end-c (and (re-search-forward cite-regexp-end limit 'end)
  2134.                    (match-beginning 0)))
  2135.            ;; skip a forwarded message
  2136.            (end-fwd (and (goto-char start)
  2137.                  (re-search-forward "---* Forwarded Message"
  2138.                             limit 'end)))
  2139.            (end (or (and end-c end-fwd (min end-c end-fwd))
  2140.                 end-c end-fwd
  2141.                 ;; defalut to limit of text.
  2142.                 (marker-position limit))))
  2143.           (goto-char start)
  2144.           (ispell-region start end)
  2145.           (if (and end-fwd (= end end-fwd))
  2146.           (progn
  2147.             (goto-char end)
  2148.             (search-forward "--- End of Forwarded Message" limit 'end))
  2149.         (goto-char end)))))
  2150.       (set-marker limit nil))))
  2151.  
  2152.  
  2153. (defun ispell-non-empty-string (string)
  2154.   (if (or (not string) (string-equal string ""))
  2155.       "\\'\\`" ; An unmatchable string if string is null.
  2156.     (regexp-quote string)))
  2157.  
  2158.  
  2159. ;;; **********************************************************************
  2160. ;;;             Buffer Local Functions
  2161. ;;; **********************************************************************
  2162.  
  2163.  
  2164. (defun ispell-accept-buffer-local-defs ()
  2165.   "Load all buffer-local information, restarting ispell when necessary."
  2166.   (ispell-buffer-local-dict)        ; May kill ispell-process.
  2167.   (ispell-buffer-local-words)        ; Will initialize ispell-process.
  2168.   (ispell-buffer-local-parsing))
  2169.  
  2170.  
  2171. (defun ispell-buffer-local-parsing ()
  2172.   "Place Ispell into parsing mode for this buffer.
  2173. Overrides the default parsing mode.
  2174. Includes latex/nroff modes and extended character mode."
  2175.   ;; (ispell-init-process) must already be called.
  2176.   (process-send-string ispell-process "!\n") ; Put process in terse mode.
  2177.   ;; We assume all major modes with "tex-mode" in them should use latex parsing
  2178.   (if (or (and (eq ispell-parser 'use-mode-name)
  2179.            (string-match "[Tt][Ee][Xx]-mode" (symbol-name major-mode)))
  2180.       (eq ispell-parser 'tex))
  2181.       (process-send-string ispell-process "+\n") ; set ispell mode to tex
  2182.     (process-send-string ispell-process "-\n"))    ; set mode to normal (nroff)
  2183.   ;; Hard-wire test for SGML mode.
  2184.   (setq ispell-skip-sgml-tags (eq 'sgml-mode major-mode))
  2185.   ;; Set default extended character mode for given buffer, if any.
  2186.   (let ((extended-char-mode (ispell-get-extended-character-mode)))
  2187.     (if extended-char-mode
  2188.     (process-send-string ispell-process (concat extended-char-mode "\n"))))
  2189.   ;; Set buffer-local parsing mode and extended character mode, if specified.
  2190.   (save-excursion
  2191.     (goto-char (point-min))
  2192.     ;; Uses last valid definition
  2193.     (while (search-forward ispell-parsing-keyword nil t)
  2194.       (let ((end (save-excursion (end-of-line) (point)))
  2195.         (case-fold-search t)
  2196.         string)
  2197.     (while (re-search-forward " *\\([^ \"]+\\)" end t)
  2198.       ;; space separated definitions.
  2199.       (setq string (buffer-substring (match-beginning 1) (match-end 1)))
  2200.       (cond ((string-match "latex-mode" string)
  2201.          (process-send-string ispell-process "+\n~tex\n"))
  2202.         ((string-match "nroff-mode" string)
  2203.          (process-send-string ispell-process "-\n~nroff"))
  2204.         ((string-match "~" string) ; Set extended character mode.
  2205.          (process-send-string ispell-process (concat string "\n")))
  2206.         (t (message "Illegal Ispell Parsing argument!")
  2207.            (sit-for 2))))))))
  2208.  
  2209.  
  2210. ;;; Can kill the current ispell process
  2211.  
  2212. (defun ispell-buffer-local-dict ()
  2213.   "Initializes local dictionary.
  2214. When a dictionary is defined in the buffer (see variable
  2215. `ispell-dictionary-keyword'), it will override the local setting
  2216. from \\[ispell-change-dictionary].
  2217. Both should not be used to define a buffer-local dictionary."
  2218.   (save-excursion
  2219.     (goto-char (point-min))
  2220.     (let (end)
  2221.       ;; Override the local variable definition.
  2222.       ;; Uses last valid definition.
  2223.       (while (search-forward ispell-dictionary-keyword nil t)
  2224.     (setq end (save-excursion (end-of-line) (point)))
  2225.     (if (re-search-forward " *\\([^ \"]+\\)" end t)
  2226.         (setq ispell-local-dictionary
  2227.           (buffer-substring (match-beginning 1) (match-end 1)))))
  2228.       (goto-char (point-min))
  2229.       (while (search-forward ispell-pdict-keyword nil t)
  2230.     (setq end (save-excursion (end-of-line) (point)))
  2231.     (if (re-search-forward " *\\([^ \"]+\\)" end t)
  2232.         (setq ispell-local-pdict
  2233.           (buffer-substring (match-beginning 1) (match-end 1)))))))
  2234.   ;; Reload if new personal dictionary defined.
  2235.   (if (and ispell-local-pdict
  2236.        (not (equal ispell-local-pdict ispell-personal-dictionary)))
  2237.       (progn
  2238.     (ispell-kill-ispell t)
  2239.     (setq ispell-personal-dictionary ispell-local-pdict)))
  2240.   ;; Reload if new dictionary defined.
  2241.   (if (and ispell-local-dictionary
  2242.        (not (equal ispell-local-dictionary ispell-dictionary)))
  2243.       (ispell-change-dictionary ispell-local-dictionary)))
  2244.  
  2245.  
  2246. (defun ispell-buffer-local-words ()
  2247.   "Loads the buffer-local dictionary in the current buffer."
  2248.   (if (and ispell-buffer-local-name
  2249.        (not (equal ispell-buffer-local-name (buffer-name))))
  2250.       (progn
  2251.     (ispell-kill-ispell t)
  2252.     (setq ispell-buffer-local-name nil)))
  2253.   (ispell-init-process)
  2254.   (save-excursion
  2255.     (goto-char (point-min))
  2256.     (while (search-forward ispell-words-keyword nil t)
  2257.       (or ispell-buffer-local-name
  2258.       (setq ispell-buffer-local-name (buffer-name)))
  2259.       (let ((end (save-excursion (end-of-line) (point)))
  2260.         string)
  2261.     ;; buffer-local words separated by a space, and can contain
  2262.     ;; any character other than a space.
  2263.     (while (re-search-forward " *\\([^ ]+\\)" end t)
  2264.       (setq string (buffer-substring (match-beginning 1) (match-end 1)))
  2265.       (process-send-string ispell-process (concat "@" string "\n")))))))
  2266.  
  2267.  
  2268. ;;; returns optionally adjusted region-end-point.
  2269.  
  2270. (defun ispell-add-per-file-word-list (word &optional reg-end)
  2271.   "Adds new word to the per-file word list."
  2272.   (or ispell-buffer-local-name
  2273.       (setq ispell-buffer-local-name (buffer-name)))
  2274.   (if (null reg-end)
  2275.       (setq reg-end 0))
  2276.   (save-excursion
  2277.     (goto-char (point-min))
  2278.     (let (case-fold-search line-okay search done string)
  2279.       (while (not done)
  2280.     (setq search (search-forward ispell-words-keyword nil 'move)
  2281.           line-okay (< (+ (length word) 1 ; 1 for space after word..
  2282.                   (progn (end-of-line) (current-column)))
  2283.                80))
  2284.     (if (or (and search line-okay)
  2285.         (null search))
  2286.         (progn
  2287.           (setq done t)
  2288.           (if (null search)
  2289.           (progn
  2290.             (open-line 1)
  2291.             (setq string (concat comment-start " "
  2292.                      ispell-words-keyword))
  2293.             ;; in case the keyword is in the middle of the file....
  2294.             (if (> reg-end (point))
  2295.             (setq reg-end (+ reg-end (length string))))
  2296.             (insert string)
  2297.             (if (and comment-end (not (equal "" comment-end)))
  2298.             (save-excursion
  2299.               (open-line 1)
  2300.               (forward-line 1)
  2301.               (insert comment-end)))))
  2302.           (if (> reg-end (point))
  2303.           (setq reg-end (+ 1 reg-end (length word))))
  2304.           (insert (concat " " word)))))))
  2305.   reg-end)
  2306.  
  2307.  
  2308. (defconst ispell-version "2.35 -- Fri Jan 13 14:16:46 EST 1995")
  2309.  
  2310. (provide 'ispell)
  2311.  
  2312.  
  2313. ;;; LOCAL VARIABLES AND BUFFER-LOCAL VALUE EXAMPLES.
  2314.  
  2315. ;;; Local Variable options:
  2316. ;;; mode: name(-mode)
  2317. ;;; eval: expression
  2318. ;;; local-variable: value
  2319.  
  2320. ;;; The following sets the buffer local dictionary to english!
  2321.  
  2322. ;;; Local Variables:
  2323. ;;; mode: emacs-lisp
  2324. ;;; comment-column: 40
  2325. ;;; ispell-local-dictionary: "english"
  2326. ;;; End:
  2327.  
  2328.  
  2329. ;;; MORE EXAMPLES OF ISPELL BUFFER-LOCAL VALUES
  2330.  
  2331. ;;; The following places this file in nroff parsing and extended char modes.
  2332. ;;; Local IspellParsing: nroff-mode ~nroff
  2333. ;;; Change IspellDict to IspellDict: to enable the following line.
  2334. ;;; Local IspellDict english
  2335. ;;; Change IspellPersDict to IspellPersDict: to enable the following line.
  2336. ;;; Local IspellPersDict ~/.ispell_lisp
  2337. ;;; The following were automatically generated by ispell using the 'A' command:
  2338. ; LocalWords:  ispell ispell-highlight-p ispell-check-comments query-replace
  2339. ; LocalWords:  ispell-query-replace-choices ispell-skip-tib non-nil tib
  2340. ; LocalWords:  regexps ispell-tib-ref-beginning ispell-tib-ref-end
  2341.  
  2342. ;; ispell.el ends here
  2343.